datetime DB issues

tanya2001

New member
Joined
Oct 18, 2007
Messages
4
Programming Experience
Beginner
hi

I am using vb.net, i have to display data on the datagridview by choosing the date(fromdate--todate)

the format i have used to enter date in the database is getdate() so it takes date and time while inserting values.

now i am using datetime picker control for the user to select the dates

i am all new to .net so i dont know what query to use to compare the datetime picker and the date in the datafield.

plz help

thanks in advance
 
Dates are compared mathematically, just like numbers. For instance, if you want to get all records where the data is before a specified date you'd do like this:
VB.NET:
myCommand.CommandText = "SELECT * FROM MyTable WHERE DateColumn < @DateColumn"
myCommand.Parameters.AddWithValue("@DateColumn", myDateTimePicker.Value)
Now, the trick is to determine what to do with the time portion of date values. You need to determine whether your column contains just dates or a time portion too. You then need to determine whether you want to filter on just the date part or the date and time.
 

Latest posts

Back
Top