Jump to content
Sign in to follow this  

Convert DATE format

Recommended Posts


How can I convert "January 2, 2006" to "02/01/2006"?

Share this post

Link to post
Share on other sites

How can I convert "January 2, 2006" to "02/01/2006"?

Lookup _DateTimeFormat in the help file.

Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post

Link to post
Share on other sites

I didn't see a convert to that type of date in the Date.au3 (of course there probably is one, and I snoozed right through it :P ), and this one will fail if the spaces aren't just right... But I'm too tired to fix it right <yawn>

$DateToConvert = 'January 2, 2006'

$MyDate = ConvertDate($DateToConvert)
MsgBox(0, "", $MyDate)

Func ConvertDate($DateToConvert)
    Local $Month[13]
    Local $NewDate
    Local $Add
    $Month[1] = "January"
    $Month[2] = "February"
    $Month[3] = "March"
    $Month[4] = "April"
    $Month[5] = "May"
    $Month[6] = "June"
    $Month[7] = "July"
    $Month[8] = "August"
    $Month[9] = "September"
    $Month[10] = "October"
    $Month[11] = "November"
    $Month[12] = "December"
    For $i = 1 To 12
        If StringInStr($DateToConvert, $Month[$i]) Then
            $Trim = StringTrimLeft($DateToConvert, StringLen($Month[$i]) + 1)
            $Day = StringSplit($Trim, ',')
            $Year = StringRight($DateToConvert, 4)
            If $i > 9 Then
                If $Day[1] < 10 Then $Add = '0'
                $NewDate = $Add & $Day[1] & "/" & $i & "/" & $Year
                Return $NewDate
                If $Day[1] < 10 Then $Add = '0'
                $NewDate = $Add & $Day[1] & "/0" & $i & "/" & $Year
                Return $NewDate
    Return 0

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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.