Date Format?
Ken Ray
kray at sonsothunder.com
Wed Jan 2 09:27:03 EST 2008
On Wed, 2 Jan 2008 13:26:11 +0000, Dave wrote:
> I have a date string in the following format:
>
> Sunday, July 13, 2003 03:07:32
>
> And I need it in this format:
>
> 2007-03-13T18:01:31Z
>
> Is there a function to do this? If not does anyone if there is any
> documentation on the latter format?
There is not a built in function to do it (that is there's no "date
format" built in), but you can parse it like this:
on mouseUp
put ReformatDate("Sunday, July 13, 2003 03:07:32") into tNewDate
-- etc.
end mouseUp
function ReformatDate pDate
convert pDate to dateItems
put (item 1 of pDate) & "-" & PZ(item 2 of pDate) & "-" & \
PZ(item 3 of pDate) & "T" & PZ(item 4 of pDate) & ":" & \
PZ(item 5 of pDate) & ":" & PZ(item 6 of pDate) & "Z" into tVal
return tVal
end ReformatDate
function PZ pNum -- PZ means "Pad Zeroes"
return format("%02d",pNum)
end PZ
Although the above code is a lot easier to understand, it is a bit
longer than you need. You can also do it with a more extensive use of
the format() function and judicious use of a quoting function ("q")
many of us have used:
function ReformatDate pDate
convert pDate to dateItems
put "%s-%02s-%02sT%02d:%02d:%02dZ" into tFormat
do "return format(" & q(tFormat) & "," & (item 1 to 6 of pDate) & ") "
end ReformatDate
function q pWhat
return quote & pWhat & quote
end q
HTH,
Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode
mailing list