date anomalies when converting to seconds

Kay C Lan lan.kc.macmail at gmail.com
Wed May 24 01:58:42 EDT 2006


On 5/24/06, Sarah Reichelt <sarah.reichelt at gmail.com> wrote:
>
> Since it seems unlikely that I will get what I want, I am gradually
> starting to use my own numeric dateTime format and conversion
> routines: YYYYMMDD, HHMMSS or the 2 combined. As well as being totally
> numeric which is great for sorting, they have the advantage of being
> human-readable.


Isn't this just dateItems without the comas. Again, although you may only
want to work with dates, specifying a 'generic' time solves heaps of
problems.

Although I wrote for Chris' problem:

put "01/06/2006" && "06:00:00" into tDate

I personally always use:

put tMyDateFromAskDialogBoxCorrectlyFormated && ",06,00,00,9" into
tMyDateTime

HOT TIP
Although you can't leave the last item blank, the great thing about
dateItems is that you can put ANY number into the last item!

put "2006,05,23,12,12,12,0" into tMyDateTime
convert tMyDateTime to dateItems
put tMyDateTime --will correctly show the last item as 3

gives the same answer as

put "2006,05,23,12,12,12,999999" into tMyDateTime
convert tMyDateTime to dateItems
put tMyDateTime --gotta be happy with that:-)

The great thing about dateItems is that it makes it so easy to add/subtract
years, months, days etc:

put "2006,05,23,12,12,12,3" into tMyDateTime
add 115 to item 3 of tMyDateTime -- could be any item
convert tMyDateTime to dateItems
put tMyDateTime

And, from the docs:

The dateItems does not change depending on the user's settings, so you can
use it (or  the seconds format) to store a date and time with a stack, in an
invariant form that won't change.

Of course you do need to be careful of the centuryCutoff property which is
supposedly set to 35, and when I "put the centuryCutoff" I get 35 but:

put "2006,05,23,12,12,12,9999999" into tMyDateTime
add 11563 to item 3 of tMyDateTime
convert tMyDateTime to dateItems
put tMyDate

result = 2038,1,18,12,12,12,2 --shouldn't be 2038 as the cutoff is 35

add another day:
put "2006,05,23,12,12,12,9999999" into tMyDateTime
add 11564 to item 3 of tMyDateTime
convert tMyDateTime to dateItems
put tMyDateTime

result = 1901,12,14,5,20,32,7 --note also that the time is no longer the
same!

And of course changing the dateItems to/from a friendly format for display,
even if you don't use Rev's short date, internet date, etc is very easy,
especially for UNIX and SQL date & times.

Hope there's something there useful for someone:-)



More information about the use-livecode mailing list