Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Interesting date formatting functions

 [1/5] from: AJMartin::orcon::net::nz at: 24-Dec-2003 22:50


These functions are pretty self explanatory: DD-MM-YYYY: func [Date [date!]] [ rejoin [pad Date/day 2 #"-" pad Date/month 2 #"-" pad Date/year 4] ]
>> dd-mm-yyyy now
== "04-12-2003" YYYYMMDD: func [Date [date!]] [ rejoin [pad Date/year 4 pad Date/month 2 pad Date/day 2] ]
>> yyyymmdd now
== "20031204" This is the interesting one/two: DD: make object! [ MM: make object! [ YYYY: func [Date [date!]] [ rejoin [pad Date/day 2 #"/" pad Date/month 2 #"/" pad Date/year 4] ] ] MMM: make object! [ YYYY: func [Date [date!]] [ rejoin [pad Date/day 2 #"/" copy/part pick Rebol/locale/Months Date/month 3 #"/" pad Date/year 4] ] ] ]
>> dd/mm/yyyy now
== "04/12/2003"
>> dd/mmm/yyyy now
== "04/Dec/2003" :) I thought they helped make it very obvious what's happening. Enjoy! Andrew J Martin Speaking in tongues and performing miracles. ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/

 [2/5] from: greggirwin:mindspring at: 4-Dec-2003 0:49


AJM> This is the interesting one/two: *Very* creative thinking Andrew! -- Gregg

 [3/5] from: petr:krenzelok:trz:cz at: 4-Dec-2003 9:13


Gregg Irwin wrote:
>AJM> This is the interesting one/two: > >*Very* creative thinking Andrew! > >-- Gregg >
not to mention 'pad function - that one has to be added to core to stop bothering me each time I need it :-) -pekr-

 [4/5] from: didec:tiscali at: 4-Dec-2003 12:24


Re: Interesting date formatting functions
> not to mention 'pad function - that one has to be added to core to stop > bothering me each time I need it :-)
YES ! And so (even if I can suppose what is it) what is the code of the 'pad func ??

 [5/5] from: AJMartin:orcon at: 24-Dec-2003 22:50


Didec wrote:
> And so (even if I can suppose what is it) what is the code of the 'pad
func ?? Here's the version I use:
>> source pad
pad: func [ {Pads a value with leading zeroes or trailing spaces or a specified fill character.} Value [any-type!] "The value." Width [integer!] "The desired width." /With Fill [char!] "With the specified Fill character." /local Operator][ Operator: either any-string? Value [ any [Fill Fill: #" "] :tail ] [ Value: form Value any [Fill Fill: #"0"] :head ] head insert/dup Operator Value Fill Width - length? Value ] Enjoy! Andrew J Martin Speaking in tongues and performing miracles. ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/