Note that there are some explanatory texts on larger screens.

plurals
  1. POEval strips time segment of a SQL DateTime field
    primarykey
    data
    text
    <p>Was going to call this "Eval won't give me the Time of Day," but thought that too cute.</p> <p>I'm kind of having the opposite problem from the suggested questions I see for my title, so here goes:</p> <p>Visual Studio 2008 Pro, SQL Express 2008, Vista. Web Project, where I'm opening records from an Event Table with JOINed info from a Facilities table.</p> <p>I have a SQL DateTime field in a SQL file that is completely filled out: e.g., 4/30/2009 6:30 PM.</p> <p>My field in the ListView is straight <code>&lt;%# Eval("EventDate") %&gt;</code>, and my trace, as far as I have been able to tell from watching the Autos window through retrieval from the SQLDataSource, survives intact with the 6:30 PM time of day.</p> <p>The only instruction, to my knowledge, that comes after the DataSource is populated, is the Eval itself.</p> <p>Yet, at render time, that datetime comes out on the page as 4/30/2009 <strong>12:00:00 AM</strong>.</p> <p>My strong belief, therefore, is that I need additional fu to parse my Eval statement to get the same time I put into the field. I am not yet adept at this, so suggestions would be welcome. Thank you in advance.</p> <p>Edit: supplying code per Jose.</p> <p>DataSource:</p> <p><code>&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:MeetingsConnectionString %&gt;" onselecting="SqlDataSource1_Selecting" SelectCommand="SELECT Events.ID, Events.FacilityID, Events.Room, Events.EventDate, Events.Speaker, Events.Topic, Facilities.ID AS Expr1, Facilities.FacilityName, Facilities.FacilityAddress, Facilities.FacilityCity, Facilities.FacilityState, Facilities.FacilityZip, Facilities.FacilityLat, Facilities.FacilityLong FROM Events INNER JOIN Facilities ON Events.FacilityID = Facilities.ID WHERE (Events.EventDate BETWEEN @EventDate AND @EventDate2) ORDER BY Events.EventDate" ProviderName="System.Data.SqlClient"&gt; &lt;SelectParameters&gt; &lt;asp:Parameter Name="EventDate" /&gt; &lt;asp:Parameter Name="EventDate2" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; </code></p> <p>ListView:</p> <p><code>&lt;asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ID,Expr1"&gt; &lt;AlternatingItemTemplate&gt; When:&lt;asp:Label ID="EventDateLabel" runat="server" Text='&lt;%# Eval("EventDate") %&gt;' /&gt; </code></p> <p>... <code>&lt;ItemTemplate&gt; When: &lt;asp:Label ID="EventDateLabel" runat="server" Text='&lt;%# Eval("EventDate") %&gt;' /&gt;&lt;br /&gt; </code></p> <p>Edit 2: I worked around the problem by separating EventDate into EventDate (a Date) and EventTime (a Time). I now get the proper values, and have moved on to conversion of the time value from military to civilian time (i.e., 6:30pm) in the SQL query using a CONVERT or CAST. Thanks for all of your responses.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload