Sign in to follow this  
Followers 0
newbie100

date format problem

11 posts in this topic

Hi, I tried to write a script as below

#include <Date.au3>
$date= "30/05/2007"
If _NowDate() < $date then
MsgBox(0, "", "date good")
Else
MsgBox(0, "", "date expired")
endif

I changed my computer's date to 01/06/2007 and runs the script. The message box with text "date good" still show up.

Is it date format problem ? Could anyone help me ? Thank you

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the forum.

From the help file under _NowDate:

If Date format isn't found in the registry it returns the date in the mm/dd/yyyy format.

...so run this code and see if the format of _NowDate is

day/month/year

or

month/day/year

#include <Date.au3>
$date = "30/05/2007"
MsgBox(0, "", _NowDate() & " < " & $date)
Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Hi,

to compare dates I would change the dates to YYYYMMDD < or > YYYYMMDD format

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Where in the registry is date format?

How can I convert to YYYMMDD?

Thanks

Control Panel | Regional and Language Options

Share this post


Link to post
Share on other sites

Welcome to the forum.

From the help file under _NowDate:

If Date format isn't found in the registry it returns the date in the mm/dd/yyyy format.

...so run this code and see if the format of _NowDate is

day/month/year

or

month/day/year

#include <Date.au3>
$date = "30/05/2007"
MsgBox(0, "", _NowDate() & " < " & $date)
Please forgive me for my late replied and thank you very much for your time.

I run the code and it return day/month/year. Does this mean the date format is found in the registry?

But if so why didn't my code works? Or it was the variable that i'd done something wrong there?

Share this post


Link to post
Share on other sites

... it return day/month/year. Does this mean the date format is found in the registry?...

It means that the date format has been set in the registry. As for why your code did not work - you asked AutoIt to compare two strings.

It would be like asking AutoIt to tell you which is greater, "this word" or "that word". Even though a date can contains numbers, it is still a string (text) until you make it a number. You can compare strings, but you might not get the results that you want.

Like Mega mentioned, it would probably be best to use the year/month/day format turned into YYYYMMDD without any "/". See if the code below makes sense to you.

#include <Date.au3>

;_NowCalcDate()
;returns the date as YYYY/MM/DD
;StringReplace(_NowCalcDate(), "/", "")
;strips out the / and returns YYYYMMDD as a string

$s_now = StringReplace(_NowCalcDate(), "/", "")
$n_now = Number($s_now) ;makes sure it is treated as a number

$date = "2007/05/30" ;the date that you enter - in YYYY/MM/DD
$s_date = StringReplace($date, "/", "")
$n_date = Number($s_date) ;makes sure it is treated as a number

MsgBox(0, "", $n_now & " < " & $n_date)
If $n_now < $n_date Then MsgBox(0, "", "less than")
If $n_now = $n_date Then MsgBox(0, "", "equal")
If $n_now > $n_date Then MsgBox(0, "", "greater than")
...and yes, I wanted 3 If statements.

newbie100 and Ed_Maximized,

You should not change the registry just to get AutoIt to return the date in the format that you want. You just need to keep looking thru the help file to find a function or User Defined Function (UDF) that will reurn the date in a format that you can then manipulate to do what you want.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

It means that the date format has been set in the registry. As for why your code did not work - you asked AutoIt to compare two strings.

It would be like asking AutoIt to tell you which is greater, "this word" or "that word". Even though a date can contains numbers, it is still a string (text) until you make it a number. You can compare strings, but you might not get the results that you want.

Like Mega mentioned, it would probably be best to use the year/month/day format turned into YYYYMMDD without any "/". See if the code below makes sense to you.

#include <Date.au3>

;_NowCalcDate()
;returns the date as YYYY/MM/DD
;StringReplace(_NowCalcDate(), "/", "")
;strips out the / and returns YYYYMMDD as a string

$s_now = StringReplace(_NowCalcDate(), "/", "")
$n_now = Number($s_now) ;makes sure it is treated as a number

$date = "2007/05/30" ;the date that you enter - in YYYY/MM/DD
$s_date = StringReplace($date, "/", "")
$n_date = Number($s_date) ;makes sure it is treated as a number

MsgBox(0, "", $n_now & " < " & $n_date)
If $n_now < $n_date Then MsgBox(0, "", "less than")
If $n_now = $n_date Then MsgBox(0, "", "equal")
If $n_now > $n_date Then MsgBox(0, "", "greater than")
...and yes, I wanted 3 If statements.

newbie100 and Ed_Maximized,

You should not change the registry just to get AutoIt to return the date in the format that you want. You just need to keep looking thru the help file to find a function or User Defined Function (UDF) that will reurn the date in a format that you can then manipulate to do what you want.

Yes I have seen my mistake, the code works well. Thank you very very much for helping me. :whistle:

Share this post


Link to post
Share on other sites

newbie100 and Ed_Maximized,

You should not change the registry just to get AutoIt to return the date in the format that you want. You just need to keep looking thru the help file to find a function or User Defined Function (UDF) that will reurn the date in a format that you can then manipulate to do what you want.

Thanks :whistle:

Share this post


Link to post
Share on other sites

You are both welcome...

-MSP-


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0