Jump to content
Sign in to follow this  
stafe

Changing a date format

Recommended Posts

stafe

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

Share this post


Link to post
Share on other sites
BrettF

$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

Share this post


Link to post
Share on other sites
stafe

$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

Share this post


Link to post
Share on other sites
BrettF

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

Share this post


Link to post
Share on other sites
stafe

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

Thanks 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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.