Jump to content

Recommended Posts

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

Lookup _DateTimeFormat in the help file.

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

Link to post
Share on other sites
  • Moderators

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.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...