469,356 Members | 2,016 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Comparing Dates In VB.NET

23
I searched before posting and followed instructions but it still did not work for me. I need to compare 2 dates but regardless of what the dates are they always return the same value on comparison. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Dim EndDate As DateTime
  2. Dim Current As DateTime = Today
  3.  
  4. If DateTime.Compare(Current, EndDate) < 0 Then
  5.     Label6.Text = "CONTRACT EXPIRED LESS THAN"
  6. End If
  7. If DateTime.Compare(Current, EndDate) = 0 Then
  8.     Label6.Text = "CONTRACT EXPIRED EQUALS"
  9. End If
  10. If DateTime.Compare(Current, EndDate) > 0 Then
  11.     Label6.Text = "CONTRACT NOT EXPIRED GREATER"
  12. End If
The EndDate is being pulled in from a database and no matter what the end date is whether is be greater or less than todays day is always displays as CONTRACT NOT EXPIRED GREATER. Anyone have an idea of what I am doing wrong? Thanks very much in advance!
Dec 28 '06 #1
4 11826
kenobewan
4,871 Expert 4TB
I suggest displaying the results first and see if there is a fortmatting problem, especially the result from the db.

Hope that this helps.
Dec 29 '06 #2
http://blogs.vbcity.com/xtab/archive/2005/12/26/5755.aspx
Dec 29 '06 #3
Hi

Use datediff() function.Pls search on google to know more about datediff() function.

Hope this helps you.
Happy coding...

I searched before posting and followed instructions but it still did not work for me. I need to compare 2 dates but regardless of what the dates are they always return the same value on comparison. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Dim EndDate As DateTime
  2. Dim Current As DateTime = Today
  3.  
  4. If DateTime.Compare(Current, EndDate) < 0 Then
  5.     Label6.Text = "CONTRACT EXPIRED LESS THAN"
  6. End If
  7. If DateTime.Compare(Current, EndDate) = 0 Then
  8.     Label6.Text = "CONTRACT EXPIRED EQUALS"
  9. End If
  10. If DateTime.Compare(Current, EndDate) > 0 Then
  11.     Label6.Text = "CONTRACT NOT EXPIRED GREATER"
  12. End If
The EndDate is being pulled in from a database and no matter what the end date is whether is be greater or less than todays day is always displays as CONTRACT NOT EXPIRED GREATER. Anyone have an idea of what I am doing wrong? Thanks very much in advance!
Dec 30 '06 #4
gderosa
23
Great thanks very much for your help I got it to work!
Jan 2 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Job Lot | last post: by
2 posts views Thread by Duppypog | last post: by
2 posts views Thread by Philip Townsend | last post: by
4 posts views Thread by Working_Girl | last post: by
12 posts views Thread by colincolehour | last post: by
2 posts views Thread by cyber100 | last post: by
4 posts views Thread by cheryl | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.