international Date

Tereza Snyder tereza at califex.com
Tue Dec 19 16:29:27 EST 2006


On Dec 19, 2006, at 5:13 AM, Sivakatirswami wrote:

> Hypenated: YYYY-MM-DD,  zero padded comes standard with SQL
> but in Rev we have to do little dances like:
>
> FUNCTION internationalDate tDate
>     convert tDate to dateitems
>     IF len(item 2 of tDate<2) THEN put "0" before item 2 of tDate
>     IF len(item 3 of tDate<2) THEN put "0" before item 2 of tDate
>     return   (item 1 of  tDate &"-" & item 2 of tDate &"-" & item 3 of
> tDate)
> END internationalDate
>
> ?? am I missing  something?

For the padding problem, look up the format function, especially this  
bit :

   Note:  If a zero is included immediately before the charLength  
parameter in any formatting incantation that allows padding, the  
resulting value is padded (if necessary) with zeroes instead of  
spaces. For example, the incantation %03s transforms "H" to "00H".

>
> Worthy of a feature request?

It would be fun to have something like:

    set the dateFormat to "YYYY-MM-DD"
    put the formattedDate

and

    set the timeFormat to "HH:MM"
    put the formattedTime

where I could even specify:

    set the timeFormat to "H hours and M minutes"

and have the formattedTime return "03 hours and 55 minutes"

or something similar.

Though with format() and merge() you can pretty much get the same  
thing :

FUNCTION internationalDate tDate
      constant k4pad="%04d", k2pad="%02d"
      constant kDateStr="[[ format(k4pad,item 1 of tDate) ]]-[[format 
(k2pad, item 2 of tDate) ]]-[[format(k2pad, item 3 of tDate) ]]"
      convert tDate to dateitems
      return merge(kDateStr)
end internationalDate

Which you can customize for different formats.


t


(Alfredo Dawes)



-- 
Tereza Snyder

    Califex Software, Inc.
    www.califexsoftware.com




More information about the use-livecode mailing list