newbie100 Posted March 9, 2007 Share Posted March 9, 2007 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 Link to comment Share on other sites More sharing options...
herewasplato Posted March 9, 2007 Share Posted March 9, 2007 (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 March 9, 2007 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 9, 2007 Share Posted March 9, 2007 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 Link to comment Share on other sites More sharing options...
Ed_Maximized Posted March 20, 2007 Share Posted March 20, 2007 Hi,to compare dates I would change the dates to YYYYMMDD < or > YYYYMMDD formatSo long,MegaWhere in the registry is date format?How can I convert to YYYMMDD?Thanks ShapedGUI Creator : Shaped gui the easy way!!!Txt2au3 : the easy way to include text files into your program without fileinstall_GUICreateWithTiledBackground : Put a GIF in the background of your formsSQLite Database BrowserAnimated GIF UDF : Put animations in your GUI's Link to comment Share on other sites More sharing options...
Gollum Posted March 20, 2007 Share Posted March 20, 2007 Where in the registry is date format?How can I convert to YYYMMDD?ThanksControl Panel | Regional and Language Options Link to comment Share on other sites More sharing options...
Ed_Maximized Posted March 20, 2007 Share Posted March 20, 2007 Control Panel | Regional and Language OptionsTHX Gollum but I said "registry" not "control panel" ShapedGUI Creator : Shaped gui the easy way!!!Txt2au3 : the easy way to include text files into your program without fileinstall_GUICreateWithTiledBackground : Put a GIF in the background of your formsSQLite Database BrowserAnimated GIF UDF : Put animations in your GUI's Link to comment Share on other sites More sharing options...
newbie100 Posted March 24, 2007 Author Share Posted March 24, 2007 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? Link to comment Share on other sites More sharing options...
herewasplato Posted March 24, 2007 Share Posted March 24, 2007 ... 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] Link to comment Share on other sites More sharing options...
newbie100 Posted March 25, 2007 Author Share Posted March 25, 2007 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. Link to comment Share on other sites More sharing options...
Ed_Maximized Posted March 25, 2007 Share Posted March 25, 2007 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 ShapedGUI Creator : Shaped gui the easy way!!!Txt2au3 : the easy way to include text files into your program without fileinstall_GUICreateWithTiledBackground : Put a GIF in the background of your formsSQLite Database BrowserAnimated GIF UDF : Put animations in your GUI's Link to comment Share on other sites More sharing options...
herewasplato Posted March 26, 2007 Share Posted March 26, 2007 You are both welcome... -MSP- [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now