Comparing date and time

G

Guest

Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30
AM. How can i compare dates .net c# or if there is any other way such as
Javascript.

Thanks

Manny
 
K

Kevin Spencer

Hi Manny,

You either have 2 DateTime values, or you have 2 strings in the format
11/22/04 9:00 AM and 11/22/04 9:30 AM. DateTime values don't have formats.
They are pure data. The System.DateTime class has many methods for comparing
DateTime values. In addition, some camparison operators can compare DateTime
values. For example:

Dim ahora As DateTime = DateTime.Now
Dim SomeDate As DateTime = SomeFunctionThatReturnsADate()
If SomeDate > ahora Then...

Note that I spoke of comparing DateTime values. DateTime is a Data Type.
Comparing 2 strings will only tell you which string is alphabetically before
the other.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
I

Ian Suttle

Manny,

If you are attempting to only compare 11/22/04 with 11/22/04 and ignore
the times, you can compare string objects of these DateTime objects
with using .ToString("d")

So a DateTime object of value {11/22/04 9:00 AM} with .ToString("d")
equates to "11/22/04"
Hope this helps!

Thanks,
Ian Suttle
http://www.IanSuttle.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top