|
-
Dec 15th, 2005, 06:18 AM
#1
Thread Starter
Junior Member
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)
-
Dec 15th, 2005, 06:21 AM
#2
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)
-
Dec 15th, 2005, 06:28 AM
#3
Thread Starter
Junior Member
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
-
Dec 15th, 2005, 06:33 AM
#4
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.
-
Dec 15th, 2005, 06:40 AM
#5
Thread Starter
Junior Member
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.
-
Dec 15th, 2005, 06:55 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|