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

YYYYMMDD date format

 [1/12] from: johnkenyon::uk::ibm::com at: 14-Nov-2000 17:31


Joel, Thanks for the tips - I'm getting there slowly ;-) john 8<-- Hi, Mat, John, Here's a QAD. zpad: func [n [number!] w [integer!] /local s] [ s: to-string n if w > length? s [ insert/dup s "0" (w - length? s) ] s ]
>> zpad 1 4 == "0001" >> zpad 123 2 == "123"
It pads to the desired length, but doesn't mess up if the number already requires more than the requested number of digits. Applying this to the original request...
>> rejoin [zpad now/year 4 zpad now/month 2 zpad now/day 2]
== "20001114" -jn-

 [2/12] from: joel:neely:fedex at: 14-Nov-2000 10:45


Hi, Mat, Well, there's a simple way to do what you want as well... (Although person's of good will might differ as to which of several approaches is "logical", given that some might want to avoid the mandatory overhead of joing strings and then immediately throwing part of the result away... ;-) [rebol-bounce--rebol--com] wrote:
> What sort of annoys me is the logical way of approaching this problem > is like this; > > value: rejoin [ "00" value ] > value: make integer! right [ value 3 ] >
Well then, define Right! right: func [s [string!] w [integer!]] [ copy at s (1 - w + length? s) ]
>> valu: right rejoin ["000" 123] 4
== "0123" -jn- -- ; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677 REBOL [] foreach [order string] sort/skip reduce [ true "!" false head reverse "rekcah" none "REBOL " prin "Just " "another " ] 2 [prin string] print ""

 [3/12] from: mat:eurogamer at: 14-Nov-2000 16:20


Heya johnkenyon, juic> pad: func [ value (integer!) figures (integer!) ] [ juic> out: copy "" juic> loop figures - length? to-string value [ append out "0" ] juic> append out value juic> ] Heh, that is is the same way I did it albeit you did it more looking like Rebol than some spastic BASIC/Arexx type stuff I did :) What sort of annoys me is the logical way of approaching this problem is like this; value: rejoin [ "00" value ] value: make integer! right [ value 3 ] All you need is keywords like left and right. Pos does mid, just dandy. juic> Arexx parse was nice but rebol parse is good fun. Just keep trying the juic> examples and you never know... I need more examples of all code. That's the way I tend to learn. The script library on rebol.com is often written by guys showing the most compact form. Unfortunately Rebol in compact form (IE with loads strings of cascading keywords in a block) is very difficult to work out. My current nightmare is trying to figure out how to do buffered reading and writing. IE reading of a big file from a URL and having it spool to a file rather than trying to be buffered (/direct just cuts off for some reason and there's no good explanation in any texts on how to use /direct properly) I need to write a copy routine which copies from one URL to another (latter being FTP), without shoving in memory. There's an example on rebol.org but this bizarrely just sends small bits of data to the FTP and appends it rather than keeping a stream going. Any clues? -- Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee http://www.eurogamer.net | http://www.eurogamer-network.com

 [4/12] from: rchristiansen:pop:isdfa:sei-it at: 14-Nov-2000 10:15


A while ago I wrote and posted a script to the REBOL library which converts the date and time to a digit format (I use it mainly for creating chronological session IDs.) Here is the link and the script for your reference: http://www.rebol.com/library/html/time-in-digits.html REBOL [] time-in-digits: func [ "Convert the date and time from 'now' into a string of digits." sun-dial [date!] "The current date and time from 'now'" ][ year: to-string sun-dial/year month: to-string sun-dial/month if (length? month) < 2 [insert month "0"] day: to-string sun-dial/day if (length? day) < 2 [insert day "0"] current-time: sun-dial/time hour: to-string current-time/hour if (length? hour) < 2 [insert hour "0"] minutes: to-string current-time/minute if (length? minutes) < 2 [insert minutes "0"] seconds: to-string current-time/second if (length? seconds) < 2 [insert seconds "0"] rejoin [year month day hour minutes seconds] ]

 [5/12] from: joel:neely:fedex at: 14-Nov-2000 10:16


Hi, Mat, John, Here's a QAD. zpad: func [n [number!] w [integer!] /local s] [ s: to-string n if w > length? s [ insert/dup s "0" (w - length? s) ] s ]
>> zpad 1 4 == "0001" >> zpad 123 2 == "123"
It pads to the desired length, but doesn't mess up if the number already requires more than the requested number of digits. Applying this to the original request...
>> rejoin [zpad now/year 4 zpad now/month 2 zpad now/day 2]
== "20001114" -jn- [rebol-bounce--rebol--com] wrote:
> Heya johnkenyon, > juic> Hi,
<<quoted lines omitted: 23>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- ; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677 REBOL [] foreach [order string] sort/skip reduce [ true "!" false head reverse "rekcah" none "REBOL " prin "Just " "another " ] 2 [prin string] print ""

 [6/12] from: g:santilli:tiscalinet:it at: 15-Nov-2000 15:35


Mat Bettinson wrote:
> The only thing that really annoys me in rebol is simple high level > string handling really. The Amigas Arexx had such easy ways to do this > sort of thing - in fact so did BASIC even.
You want LEFT and RIGHT, don't you? It's so simple: left: func [ string [string!] n [integer!] /with char [char!] ] [ head insert/dup tail copy/part string n any [char #" "] subtract n length? string ] or, in a more readable fashion: left: func [ string [string!] n [integer!] /with char [char!] ] [ char: any [char #" "] string: copy/part string n insert/dup tail string char n - length? string string ]
>> left "abc" 0
== ""
>> left "abc" 1
== "a"
>> left "abc" 2
== "ab"
>> left "abc" 10
== "abc "
>> left/with "abc" 10 #"-"
== "abc-------" right: func [ string [string!] n [integer!] /with char [char!] ] [ head insert/dup copy/part tail string negate n any [char #" "] n - length? string ]
>> right "abc" 0
== ""
>> right "abc" 1
== "c"
>> right "abc" 2
== "bc"
>> right "abc" 10
== " abc"
>> right/with "1" 2 #"0"
== "01"
>> zero-pad: func [val [integer!] n] [right/with form val n #"0"] >> zero-pad 5 2
== "05"
>> zero-pad 5 4
== "0005"
> Tell you something else I'd give my left one for, a straight port of > the Arexx parse command. I don't think I'll *ever* understand Rebols > :(
You will; it's simpler than Arexx and is *MUCH* more powerful! HTH, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [7/12] from: carlos:lorenz at: 14-Nov-2000 11:24


Hi, I was wondering how can I get the date formatted as YYYYMMDD? Carlos

 [8/12] from: mat:eurogamer at: 14-Nov-2000 14:00


Heya Mailbank, M> I was wondering how can I get M> the date formatted as YYYYMMDD? nowdate: rejoin [ now/year now/month now/day ] ? -- Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee http://www.eurogamer.net | http://www.eurogamer-network.com

 [9/12] from: arolls:bigpond:au at: 15-Nov-2000 1:02


Hi Carlos,
> I was wondering how can I get > the date formatted as YYYYMMDD? > > Carlos
Try this:
>> date: now/date
== 15-Nov-2000
>> repeat a 3 [append "" date/:a]
== "20001115" or
>> rejoin [date/1 date/2 date/3]
== "20001115" Anton

 [10/12] from: johnkenyon:ibm at: 14-Nov-2000 14:39


Hi, now/month returns 1 not 01 for month in Jan so .. nowdate: rejoin [ now/year either now/month < 10 [ "0" ] [ "" ] now/month now/day ] cheers, john 8<-- Heya Mailbank, M> I was wondering how can I get M> the date formatted as YYYYMMDD? nowdate: rejoin [ now/year now/month now/day ] ? -- Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee http://www.eurogamer.net | http://www.eurogamer-network.com

 [11/12] from: mat:eurogamer at: 14-Nov-2000 14:31


Heya johnkenyon, juic> Hi, juic> now/month returns 1 not 01 for month in Jan so .. juic> nowdate: rejoin [ now/year either now/month < 10 [ "0" ] [ "" ] now/month juic> now/day ] Mmmm, that's interesting. I bet you could use that to make a VASTLY more elegant solution to my rather disgusting hack to generate some serial numbers with padded zeros. How could you extend that for a 3 digit issue? IE 0-9 10-99 100-999 I'd show you how I did it but it's really quite embarrassing ;) The only thing that really annoys me in rebol is simple high level string handling really. The Amigas Arexx had such easy ways to do this sort of thing - in fact so did BASIC even. Tell you something else I'd give my left one for, a straight port of the Arexx parse command. I don't think I'll *ever* understand Rebols :( -- Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee http://www.eurogamer.net | http://www.eurogamer-network.com

 [12/12] from: johnkenyon:ibm at: 14-Nov-2000 16:10


Mat, Probably no neater - but here goes ... pad: func [ value (integer!) figures (integer!) ] [ out: copy "" loop figures - length? to-string value [ append out "0" ] append out value ]
>I'd show you how I did it but it's really quite embarrassing ;)
I'm not much further ahead than you are :)
>Tell you something else I'd give my left one for, a straight port of >the Arexx parse command. I don't think I'll *ever* understand Rebols >:(
Arexx parse was nice but rebol parse is good fun. Just keep trying the examples and you never know... Cheers, John

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted