Results 1 to 6 of 6

Thread: Compare Only Date not the Time (datetimepicker)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    19

    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)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Date.Compare(date1.Date, date2.Date)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    19

    Resolved 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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    19

    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.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width