Last post Dec 20, 2010 03:44 PM by daytonasteve
Dec 19, 2010 11:00 AM|daytonasteve|LINK
Novice skill level here, please be gentle.
I've written this code to display a group of events when the value is 12/19/2010. This means each day I need to change the "default value" to the current date to display the events of the day. I would like to make this such that the change occurs automatically,
that is, on 12/20/2010, I'd like to see just the events for 12/20/2010.
<asp:SqlDataSource ID="testeventdate" runat="server" ConnectionString="<%$ ConnectionStrings:testdateConnectionString %>" SelectCommand="SELECT [eventDate], [eventDesc] FROM [programEvents] WHERE ([eventDate] = @eventDate)">
<asp:querystringparameter DefaultValue="12/19/2010" Name="eventDate" QueryStringField="eventDate" Type="DateTime" />
Any advice would be much appreciated.
Dec 19, 2010 07:33 PM|PeteNet|LINK
Yeah, you should be able to compare directly to whichever is your DateTime column using GetDate()
"...WHERE ......startTime = GetDate()"
Dec 20, 2010 09:28 AM|daytonasteve|LINK
I added the GetDate() to my code. The result is an empty grid, even though I have events for every day of the month. I suspect part of the problem is the the "default value 12/19/2010" statement but I'm not sure what to do with that.
Dec 20, 2010 10:04 AM|PeteNet|LINK
I added the GetDate() to my code.
show us what you did.
Also, you don't need "[eventDate] = @eventDate" and the QueryStringParameter 'EventDate' and you can remove the same.
IF eventDate is the DateTime column, you needed to do this: WHERE ([eventDate] = GetDate())"
Dec 20, 2010 03:44 PM|daytonasteve|LINK
I have no idea why this works but so far it seems to be OK.
<asp:SqlDataSource ID="testeventdate" runat="server" ConnectionString="<%$ ConnectionStrings:testeventConnectionString %>" SelectCommand="SELECT [eventDate], [eventDesc] FROM [programEvents] WHERE ([eventDate] = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())))
ORDER BY [eventDate], [startTime]">
Something about the time at 12:00:00. Not sure why that is relevant since my event date is in a date column, not a datetime, but it seems to be working.