Showing only present and future dates using SelectCommand in ASP.NET
Where you have a database of events you can easily exclude those which have gone by leaving only current and future events. However, getting the SelectCommand syntax right is not obvious.
SelectCommand=”SELECT [EventName], [EventDate] FROM [EventsTable] WHERE DateValue([EventDate]) >= DATE() ORDER BY [EventDate]“
To show only current and future events add DateValue([EventDate]) >= DATE() to the WHERE clause of your data source SelectCommand. DateValue grabs the date value of your date field, DATE() returns today’s date.
This can be varied to show dates in the past by changing the operator from “>=” to “<” or past and present “<=”.
Works with ASP.NET 2.0 or higher.
| Print article | This entry was posted by admin on March 11, 2009 at 11:15 am, and is filed under ASP.NET, SQL, SelectCommand. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |


about 1 year ago
Is it possible to use an SQL statement to select a series of dates (maybe a month’s worth) as column names and list the events under the column of the date that the event occur? Like a calendar table.