Compare Only Date not the Time (datetimepicker)
Hallo,
i have a problem with comparing two DateTimePickers, which both have the same date.
but with Date.Compare(date1, date2) a voll comparsion with date and time is done.
how can i just compare the dates..
(I have searched the forum and msdn...nothing found)
Re: Compare Only Date not the Time (datetimepicker)
If you want to get just the date portion of a DateTime object you get its Date property. This returns another DateTime object with the same date but the time portion zeroed to midnight:
VB Code:
Date.Compare(date1.Date, date2.Date)
Re: Compare Only Date not the Time (datetimepicker)
yes i have been tried this. should work but it didn't..
I solve the problem with taking only the DateValue:
From "15.12.2005 13:25:00" i take just the .SubString(0,10) and compare it..
hope it works
thanks
Re: Compare Only Date not the Time (datetimepicker)
Why are you dealing with strings? Are you using the Value property of the DTP or the Text property?
VB Code:
Date.Compare(dtp1.Value.Date, dtp2.Value.Date)
If that doesn't work then you are doing something wrong. I recommend against using a hack workaround for a problem that doesn't exist.
Re: Compare Only Date not the Time (datetimepicker)
sorry with DTP is your suggestion ok.
problem was: that i read my data from sqlerver and datetime-objects are saved with full length (date and time)..that why i play with strings.
Re: Compare Only Date not the Time (datetimepicker)
A DateTime object is a DateTime object, wherever it comes from. If your query returns date/time values rather than strings then cast them as DateTime objects and use their Date property. Only if your query actually returns strings should you be working with strings.