Help needed in retrieving time from the DateTime field

Last post 05-09-2008 9:09 AM by guardianhm. 6 replies.

Sort Posts:

  • Help needed in retrieving time from the DateTime field

    05-09-2008, 4:37 AM
    • Loading...
    • guardianhm
    • Joined on 05-26-2007, 11:09 AM
    • Posts 20
    Hey!

    I am trying to display the SatrtTime and the EndTime in the gridview as follow,

    Start - End
    9:00:00 - 10:00:00

    <asp:TemplateField HeaderText="Start - End">
    <ItemTemplate>
    <asp:Literal ID="litTimeRange" runat="server" Text='<%# Eval("StartTime") + " - " + Eval("EndTime") %>'>
    </asp:Literal>
    </ItemTemplate>
    </asp:TemplateField>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ScheduleConnectionString %>"
    SelectCommand="SELECT ID, StartTime, EndTime, CompanyName, Purpose, AccountManager, Presenter, ColorCode, Status, Comments FROM Demo_Theatre_DB WHERE (StartTime &gt;= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)) AND (StartTime &lt;= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1))">
    </asp:SqlDataSource>

    I do not know where and how to do tha coding for that.

    Hope someone can help me.

    Thanks!
  • Re: Help needed in retrieving time from the DateTime field

    05-09-2008, 4:54 AM

    Hello,

    You can ignore the Literal, try this

      

    <asp:TemplateField HeaderText="Start - End">
    <ItemTemplate>
    <%# Bind("StartTime") + " - " + Bind("EndTime") %>
    </asp:Literal>
    </ItemTemplate>
    </asp:TemplateField>

     

    If you are using VB.NET then change the plus(+) to & 

    Regards 

  • Re: Help needed in retrieving time from the DateTime field

    05-09-2008, 5:52 AM
    • Loading...
    • guardianhm
    • Joined on 05-26-2007, 11:09 AM
    • Posts 20
    Thanks smiling4ever. But, how do I just get the time from the DateTime field.
  • Re: Help needed in retrieving time from the DateTime field

    05-09-2008, 6:56 AM

    The following posts might be useful in your case

    http://forums.asp.net/t/1008356.aspx

    http://forums.databasejournal.com/archive/index.php/t-25048.html

     

    Regards 

  • Re: Help needed in retrieving time from the DateTime field

    05-09-2008, 8:45 AM
    • Loading...
    • guardianhm
    • Joined on 05-26-2007, 11:09 AM
    • Posts 20
    Thanks for pointing me to the posts. It was really helpful.

    But I am still having a problem.

    I tried to code as follow, but an error is thrown saying that DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'StartTime'.

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ScheduleConnectionString %>" SelectCommand="SELECT ID, Convert(Char(5), StartTime, 114), Convert(Char(5), EndTime, 114), CompanyName, Purpose, AccountManager, Presenter, ColorCode, Status, Comments FROM Demo_Theatre_DB WHERE (StartTime &gt;= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)) AND (StartTime &lt;= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1))">
    </asp:SqlDataSource>

    Your help will be appreciated.

    Thanks
  • Re: Help needed in retrieving time from the DateTime field

    05-09-2008, 8:57 AM
    Answer

    Hello,

     Use this
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ScheduleConnectionString %>" SelectCommand="SELECT ID, Convert(Char(5), StartTime, 114) As StartTime, Convert(Char(5), EndTime, 114) As EndTime, CompanyName, Purpose, AccountManager, Presenter, ColorCode, Status, Comments FROM Demo_Theatre_DB WHERE (StartTime >= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)) AND (StartTime <= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1))">
    </asp:SqlDataSource>
     
  • Re: Help needed in retrieving time from the DateTime field

    05-09-2008, 9:09 AM
    • Loading...
    • guardianhm
    • Joined on 05-26-2007, 11:09 AM
    • Posts 20
    Thanks! It works!
Page 1 of 1 (7 items)