• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

How can I compare 2 DateTimePicker control (configre to display only time) for the time and not the date?

I'm using the following code but it's using the Date of the control and time during the comparison.  I only want to compare the time,   how can I do that?  Thanks.
 if ((toTime.Value.CompareTo(fromTime.Value)) < 0)
0
lapucca
Asked:
lapucca
1 Solution
 
Ravi SinghSenior Software EngineerCommented:
Hi, you can use the TimeOfDay property on the DateTime object:

if (toTime.Value.TimeOfDay < fromTime.Value.TimeOfDay)
{
             
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now