473,326 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Comparing dates

I'd like to compare two dates... a string as "0306" to the date of the system clock in vb.net. If I have a string "0306", this is the format month and year. I'd like to compare it to the month and year of the system clock and see which is greater. Thanks.
Nov 20 '05 #1
3 4379
Bryan,

Something like this should do it:

<code (VB.NET) >

Dim adate As Date = Now
If CInt(Microsoft.VisualBasic.Right(strDate, 2)) + 2000 < adate.Year
OrElse CInt(Microsoft.VisualBasic.Left(strDate, 2)) < adate.Month Then
Console.WriteLine(strDate + " is less than " + Format(adate, "MMyy"))
ElseIf CInt(Microsoft.VisualBasic.Right(strDate, 2)) + 2000 = adate.Year
And CInt(Microsoft.VisualBasic.Left(strDate, 2)) = adate.Month Then
Console.WriteLine(strDate + " is equal to " + Format(adate, "MMyy"))
Else
Console.WriteLine(strDate + " is greater than " + Format(adate, "MMyy"))
End If

</code>

-Sam Matzen
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
I'd like to compare two dates... a string as "0306" to the date of the

system clock in vb.net. If I have a string "0306", this is the format month
and year. I'd like to compare it to the month and year of the system clock
and see which is greater. Thanks.
Nov 20 '05 #2
Thanks Samuel... most helpful.

"Samuel L Matzen" wrote:
Bryan,

Something like this should do it:

<code (VB.NET) >

Dim adate As Date = Now
If CInt(Microsoft.VisualBasic.Right(strDate, 2)) + 2000 < adate.Year
OrElse CInt(Microsoft.VisualBasic.Left(strDate, 2)) < adate.Month Then
Console.WriteLine(strDate + " is less than " + Format(adate, "MMyy"))
ElseIf CInt(Microsoft.VisualBasic.Right(strDate, 2)) + 2000 = adate.Year
And CInt(Microsoft.VisualBasic.Left(strDate, 2)) = adate.Month Then
Console.WriteLine(strDate + " is equal to " + Format(adate, "MMyy"))
Else
Console.WriteLine(strDate + " is greater than " + Format(adate, "MMyy"))
End If

</code>

-Sam Matzen
"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
I'd like to compare two dates... a string as "0306" to the date of the

system clock in vb.net. If I have a string "0306", this is the format month
and year. I'd like to compare it to the month and year of the system clock
and see which is greater. Thanks.

Nov 20 '05 #3
Bryan,
In addition to Samual's suggestion, if I had a string & needed to compare
it to a date, I would either convert the Date to a string or convert the
string to a Date. Because your string has less detail, its missing the day,
I would convert the date to the format of the string.

Something like:

If "0306" > DateTime.Today.ToString("MMyy") Then
' "0306" is greater
End If

For information on formatting types (such as using the ToString method) see
"Formatting Types"

http://msdn.microsoft.com/library/de...ttingtypes.asp

For information on custom DateTime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

Hope this helps
Jay

"Bryan" <Br***@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
I'd like to compare two dates... a string as "0306" to the date of the

system clock in vb.net. If I have a string "0306", this is the format month
and year. I'd like to compare it to the month and year of the system clock
and see which is greater. Thanks.
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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
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...
2
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...
4
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...
12
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...
4
by: gderosa | last post by:
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. ...
2
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...
4
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...
2
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...
1
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.