Jump to content

Converting a Month to a number using autoit...


Recommended Posts

As you can see below my format is like 2014/May/26 or May 26, 2014 date.

To use the autoit below I need to reformat to 2014/05/26.. is there an autoit command that will convert the month for example May into the digit 5.... or convert month to digit...so I can run it thru the script as shown.

#include <Date.au3>
#include <MsgBoxConstants.au3>

; Below is the format I have.. 
; Myformat = 2014/May/26

; Below is the format I need....
$mytime = "2014/05/26"

MsgBox($MB_SYSTEMMODAL, "Current Time", $mytime)
; Show current date/time in the pc's format
MsgBox($MB_SYSTEMMODAL, "Pc Short format", _DateTimeFormat($mytime, 2))
MsgBox($MB_SYSTEMMODAL, "Pc Long format", _DateTimeFormat($mytime, 1))
Link to comment
Share on other sites

Something like this should work:

Global $example1 = '2014/May/26'
Global $example2 = '2014/Jan/15'
Global $example3 = '2014/Apr/03'

MsgBox(0, "message", $example1 & '  ->  ' & _ConvertMonth($example1))
MsgBox(0, "message", $example2 & '  ->  ' & _ConvertMonth($example2))
MsgBox(0, "message", $example3 & '  ->  ' & _ConvertMonth($example3))

Func _ConvertMonth($date)
   $date = StringReplace($date, '/Jan/', '/01/')
   $date = StringReplace($date, '/Feb/', '/02/')
   $date = StringReplace($date, '/Mar/', '/03/')
   $date = StringReplace($date, '/Apr/', '/04/')
   $date = StringReplace($date, '/May/', '/05/')
   $date = StringReplace($date, '/Jun/', '/06/')
   $date = StringReplace($date, '/Jul/', '/07/')
   $date = StringReplace($date, '/Aug/', '/08/')
   $date = StringReplace($date, '/Sep/', '/09/')
   $date = StringReplace($date, '/Oct/', '/10/')
   $date = StringReplace($date, '/Nov/', '/11/')
   $date = StringReplace($date, '/Dec/', '/12/')
   Return $date
EndFunc
Link to comment
Share on other sites

Thanks... i had already thought of that.. but I was sure that with all the date/time commands it would be in there somewhere... wild to have to do it manually.... however this does solve the problem so if no one else comes up with the already written code then I will mark this solved and go the dark ages way...Below is what I have been using but I was sure there would be an autoit command.... Thanks for the help... anyway...

Local $d[12] = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']

$a = "May:6:2014"

$b = stringsplit($a, ":")

   for $x = 1 to 12
      if $d[$x] = $b[1] then ExitLoop
   Next

$mytime = $b[3] & '/' & $x & '/' & $b[2]
consolewrite($mytime & @CRLF)

MsgBox(0, "Current Time", $mytime)
; Show current date/time in the pc's format
MsgBox(0, "Pc Short format", _DateTimeFormat($mytime, 2))
MsgBox(0, "Pc Long format", _DateTimeFormat($mytime, 1))
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...