473,699 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparing Dates In VB.NET

23 New Member
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 12468
kenobewan
4,871 Recognized Expert Specialist
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
digitalmanic
24 New Member
http://blogs.vbcity.co m/xtab/archive/2005/12/26/5755.aspx
Dec 29 '06 #3
ashima515
40 New Member
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 New Member
Great thanks very much for your help I got it to work!
Jan 2 '07 #5

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

Similar topics

3
2140
by: Job Lot | last post by:
How can compare two dates in terms of months. i.e. 01/08/2004 = 10/08/2004 05/08/2004 < 01/08/2005 thanx
2
1835
by: Duppypog | last post by:
I'm trying to compare a date stored in a database with today's date using an If statement, but it's not returning true. Example, value in database is 11/5/2003 with today being 11/6/2003. Can someone spot the problem? Thanks, Lynnette Here's the code: sSQL = "Select PWExpire FROM tblUsers where strUserName = '" & stUser & "' AND strPassword = '" & hshPW & "'"
2
1587
by: Philip Townsend | last post by:
I am having difficulty with a simple routine as follows: public static bool VerifyExpirationDate(DateTime date) { if(date>=DateTime.Now)return true; else return false; } The problem is that when today's date is passed in, the method returns false. Any ideas? Thanks!
4
2643
by: Working_Girl | last post by:
Hi, I have a database with insurance clients and their dependents (spouses and children). We had a problem in the past with the twins and some of them have been entered with one month difference in their dates of birth, some of them have the same dates of births. I need to query both cases. In the case where they are set up with one month difference, the dates of birth has to be within 4 months of each other and excluding the ones...
12
5557
by: colincolehour | last post by:
I am new to Python and am working on my first program. I am trying to compare a date I found on a website to todays date. The problem I have is the website only shows 3 letter month name and the date. Example: Jun 15 How would I go about comparing that to a different date? The purpose of my program is to load a webpage and see if the content on the front page is fresh or stale as in older than a few days. Any help in the right direction...
2
4141
by: cyber100 | last post by:
Is there an easy way to calculate how many days between two dates.. i have two dates and want to work out how many days between them, i have a static date and was getting todays date then working out for each what the day of the year was and subtracting the two, this worked fine until the new year.. now i have dates from 2006 and todays date of 2007 and obviously cant use the day of the year function as the 2007 date is less than the 2006...
4
2350
by: cheryl | last post by:
I am using the PHP.MYSQL and Apache server application in developing my website. I have problem in comparing dates. Website has room reservation, the user will check first the room availability. The user will input dates using the combo box like cboyear,cboday and cbomonth. What SQL statement or quey should I write to compare it to the database. The database has already have value in dates. I want to compare the input date to the database.......
2
2183
by: Twanne | last post by:
How do you compare dates that are in dd/mm/yyyy format?? Al my dates are stored like this but access keeps checking them by mm/dd/yyy format. When access can't convert my dd/mm/yyyy format, it uses the date i stored. If access can convert it to mm/dd/yyyy format and it still is a legal date it does so. How do I get around this?? Greetz
1
1720
by: ckmoied | last post by:
Hi all, How can I compare the dates in a column in two separate tables. Actually some of the dates in Table A are missing in Table B. I want to identify those dates. Thanks
0
8687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9034
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8883
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.