stafe Posted January 20, 2009 Share Posted January 20, 2009 I have written a script that returns a date in a dd/mm/yyyy format. I am trying to convert it into yy-mm-dd format. I have not a lot of experience here but I can not find an easy solution. Any suggestions would be appreciated. Simon Link to comment Share on other sites More sharing options...
BrettF Posted January 20, 2009 Share Posted January 20, 2009 $date = "20/01/2009" MsgBox (0, $date & "(dd/mm/yyyy)", _EditDate ($date) & " (yy-mm-dd)") Func _EditDate ($datestr) $sD = StringSplit ($datestr, "/") $day = StringRight ($sD[1], 2) $month = StringRight ($sD[2], 2) $year = StringRight ($sD[3], 2) Return $year & "-" & $month & "-" & $day EndFunc Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
stafe Posted January 20, 2009 Author Share Posted January 20, 2009 $date = "20/01/2009" MsgBox (0, $date & "(dd/mm/yyyy)", _EditDate ($date) & " (yy-mm-dd)") Func _EditDate ($datestr) $sD = StringSplit ($datestr, "/") $day = StringRight ($sD[1], 2) $month = StringRight ($sD[2], 2) $year = StringRight ($sD[3], 2) Return $year & "-" & $month & "-" & $day EndFunc Brett Thank you for your reply. I tried it in my code and it returned an error: Variable used without being declared The odd thing is that I have declared all the variable. Could the problem be that the date that I am inputing in your function may not be in string format but in date format. I got the date by using $MyDate = GUICtrlCreateDate("bla", 5, 60, 200, 20, $DTS_SHORTDATEFORMAT) and then getting the final date in a loop using $mydate2 = GUICtrlRead($MyDate) Do you have any suggestions? Thank you Simon Link to comment Share on other sites More sharing options...
BrettF Posted January 20, 2009 Share Posted January 20, 2009 Are you using Opt("MustDeclareVars", 1) at all? Because then you will need to declare all the variables in the function. Are you using the full version of SciTe? Paste the console output here too Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
stafe Posted January 20, 2009 Author Share Posted January 20, 2009 Are you using Opt("MustDeclareVars", 1) at all?Because then you will need to declare all the variables in the function.Are you using the full version of SciTe? Paste the console output here too Cheers,BrettThanks Bret,I have discovered the problem. It was my error. I forgot to insert the #Include <DateTimeConstants.au3>It now works perfectly.Thanks again - you saved me a lot of time and bother. Much appreciated.Simon 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