By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

Comparing date and time

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

"Manny Chohan" <Ma*********@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
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

Nov 18 '05 #2

P: n/a
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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.