ISO 8601 date to seconds
Bob Sneidar
bobsneidar at iotecdigital.com
Thu Jan 29 11:20:35 EST 2015
Sorry about the extra lines in the last post. Not sure what caused that. Here is the formatDate() function as well.
Bob S
function formatDate theDate, theFormat
/*
Accepts any valid date for the first parameter. If not a valid date, it simply returns
what was passed. Second parameter can be any of the following:
sql date: date in the yyyy-mm-dd format
short date, abbreviated date, internet date, long date: LC versions of the same
julian date: Julian number based on (I believe) Jacques formula)
*/
put the itemdelimiter into theOldDelim
set the itemdelimiter to "-"
if the length of item 1 of theDate = 4 and \
the number of items of theDate = 3 and \
item 1 of theDate is a number and \
item 2 of theDate is a number and \
item 3 of theDate is a number then
put item 2 of theDate & "/" & \
item 3 of theDate & "/" & \
item 1 of theDate into theDate
end if
convert theDate to dateitems
set the itemdelimiter to theOldDelim
switch theFormat
case "sql date"
put item 1 of theDate & "-" & \
format("%02d",item 2 of theDate) & "-" & \
format("%02d",item 3 of theDate) into theDate
break
case "short date"
convert theDate from dateitems to short date
break
case "abbreviated date"
convert theDate from dateitems to abbreviated date
break
case "internet date"
convert theDate from dateitems to internet date
break
case "long date"
convert theDate from dateitems to long date
break
case "julian date"
put the date into theDate
convert theDate to dateItems
if ((item 2 of theDate = 1) or (item 2 of theDate = 2)) then
put 1 into theDay
else
put 0 into theDay
end if
put item 1 of theDate + 4800 - theDay into theYear
put item 2 of theDate + (12 * theDay) - 3 into theMonth
put item 3 of theDate + \
((153 * theMonth + 2) div 5) + \
(365 * theYear) + \
(theYear div 4) - \
(theYear div 100) + \
(theYear div 400) - \
32045 into theDate
break
end switch
return theDate
end formatDate
> On Jan 29, 2015, at 08:05 , Bob Sneidar <bobsneidar at iotecdigital.com> wrote:
>
> Not that this solves your particular problem but some might be interested in this function. I will see if I can include this scenario in my function at some point.
>
> Bob S
More information about the use-livecode
mailing list