Jump to content

Date Help


wutzke
 Share

Recommended Posts

How would you convert

09/25/2006

to

Sep 25, 06

There have been MANY UDFs written for date formatting, so a little searching may turn up more elegant answers, but:

You could split the string up by StringSplit(), using the forward slash as the delimiter, then convert each of the three parts to the desired format. Do you do arrays yet? Arrays will give you everything you need.

The following code splits the original to parts in an array called $DateSplit:

$DateIn = "09/25/2006"
$DateSplit = StringSplit($DateIn, "/")

Now the contents of that array are:

$DateSplit[0] = 3 ; Count

$DateSplit[1] = "09"

$DateSplit[2] = "25"

$DateSplit[3] = "2006"

Hope that helps.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks

so perhaps ...

Global $A_Mon[13] = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
$DateIn = "09/25/2006"
$DateSplit = StringSplit($DateIn, "/")
$theMonthNum=$DateSplit[1] 
$theMonth=$A_Mon[$DateSplit[1]]
$theYear=StringRight($DateSplit[3],2)
$newdate = $theMonth & " " & $DateSplit[2] & ", " & $theYear

could be a way the convert a date put into the datein var

Link to comment
Share on other sites

Thanks

so perhaps ...

Global $A_Mon[13] = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
$DateIn = "09/25/2006"
$DateSplit = StringSplit($DateIn, "/")
$theMonthNum=$DateSplit[1] 
$theMonth=$A_Mon[$DateSplit[1]]
$theYear=StringRight($DateSplit[3],2)
$newdate = $theMonth & " " & $DateSplit[2] & ", " & $theYear

could be a way the convert a date put into the datein var

yeah looks good to me ;)
Link to comment
Share on other sites

  • Moderators

$sDateIn = _DateToString("09/25/2006")
MsgBox(64, 'Info', $sDateIn)

Func _DateToString($sDate)
    Local $aMon[13] = ['','Jan','Feb','March','April','May','June','July','Aug','Sep','Oct','Nov','Dec']
    Local $aDate = StringRegExp($sDate, '^(\d{1,2})/(\d{1,2})/(\d{2}|\d{4})$', 1)
    If IsArray($aDate) Then Return $aMon[Int($aDate[0])] & ' ' & $aDate[1] & ', ' & $aDate[2]
    Return SetError(1, 0, 0)
EndFunc

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 comment
Share on other sites

$sDateIn = _DateToString("09/25/2006")
MsgBox(64, 'Info', $sDateIn)

Func _DateToString($sDate)
    Local $aMon[13] = ['','Jan','Feb','March','April','May','June','July','Aug','Sep','Oct','Nov','Dec']
    Local $aDate = StringRegExp($sDate, '^(\d{1,2})/(\d{1,2})/(\d{2}|\d{4})$', 1)
    If IsArray($aDate) Then Return $aMon[Int($aDate[0])] & ' ' & $aDate[1] & ', ' & $aDate[2]
    Return SetError(1, 0, 0)
EndFunc
hahah was going to do stringreg but was to lazy since he already wrote a script that worked xD
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...