472,108 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,108 software developers and data experts.

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 12151
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.