Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:38:16+00:00 2026-06-11T15:38:16+00:00

I have a form with two DateTimePicker controls DateTime.Compare should return 0 if they

  • 0

I have a form with two DateTimePicker controls

DateTime.Compare should return 0 if they have the same value, but it thinks they are not the same:

?DateTime.Compare(DatePicker.dtpFrom.Value, DatePicker.dtpTo.Value)
1

?datepicker.dtpFrom.Value
#9/20/2012 7:00:46 PM#

?DatePicker.dtpTo.Value
#9/20/2012 7:00:46 PM#

Am I somehow not thinking clearly? Surely this isn’t some bug in the .NET Framework.

UPDATE
OK I checked the millisecond values and they are off (very slightly). Quirky! I guess it has to do with some subtle delay when the controls are constructed and their default values are set.

?DatePicker.dtpTo.value.ToString("fff")
"616"
?datepicker.dtpFrom.Value.ToString("fff")
"619"

I only care about the date portion, so I solved it:

If DateTime.Compare(DatePicker.dtpFrom.Value.Date, DatePicker.dtpTo.Value.Date) > 0 Then
                MsgBox("From_Date cannot be after To_Date", MsgBoxStyle.OkOnly, "Data validation error")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:38:18+00:00Added an answer on June 11, 2026 at 3:38 pm

    Be careful when comparing multiple DateTimePicker controls. Small differences in the millisecond portion of their values can cause unexpected comparison results, even when no user has edited their default values.

    For example, say you have two DateTimePicker controls on your form: FromDate and ToDate, used to establish a date range for a report.

    As the question above shows, comparing the two values to ensure that the FromDate is not greater than the ToDate, can result in unexpected results.

    If you only care about the Date portion of these controls, you can drop the time value when doing the comparison by reading the Date property on the Value property.

    If DateTime.Compare(dtpFrom.Value.Date), DateValue(dtpTo.Value.Date) > 0 Then
    {invalid range error message}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form, with two DateTimePicker-controls: One for date, and one for
I have form with two buttons having same name but different values ,how to
i have two form in my sites but both are submitting on same action
I have one form and two submit buttons. at the moment they are like
I have a form with two inputs: <input type="text" name="keyword" value="Search" onfocus="wipe(this)"/> <input type="text"
In one page I have two form for search: <form class=search-panel method=post action= onsubmit=return
I guys i'm using a datetimepicker by trentrichardson.com. I have a form with two
If I have a form with two checkboxes that have have the same array
I have two form fields on my view page, a date input (with a
I have a form with two input text fields: <input id=ModelName_test_0 name=ModelName[test][0] type=text> <input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.