开发者

Change format of existing date

I am trying to format a date to look like this 2011-09-19

If I do the following :

leaveDate = "09/19/11"
FormatTime, fileDate, leaveDate, yyyy-MM-dd
MsgBox, %fileDate%开发者_如何学运维

It will just pick up the current date and time because my input date format is invalid. How can I take this 09/19/11 and turn it into this 2011-09-19?

I have read the docs, and I can't find a function to do this. Am I just overlooking it?


Your date needs to be supplied in YYYYMMDDHH24MISS format. If your date format is consistent and all years are after 2000 then the following code using SubStr() to split up the date should work:

leaveDate := "09/19/11"

year := "20" . SubStr(leaveDate, 8, 2)
month := SubStr(leaveDate, 2, 2)
date := SubStr(leaveDate, 5, 2)
formattedTime := year . month . date

FormatTime, fileDate, %formattedTime%, yyyy-MM-dd
MsgBox, %fileDate%

At the bottom of the documentation page for FormatTime a link is given to a forum topic giving the code for a function titled DateParse. This function will take a date in pretty much any format and return a YYYYMMDDHH24MISS formatted string that can be used instead of SubStr() generated string.

The example given is:

DateParse("2:35 PM, 27 November 2007") 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜