Great! Glad to know it is possible. I wouldn't have guessed a leading zero would use r (called background text in the dictionary)
Thanks On Wed, Apr 4, 2018, 9:36 PM Tom Arneson <[email protected]> wrote: > This puts leading zeros with 8!:2 > > 'q<->5.0,q<->r<0>3.0,r<0>2.0' 8!:2[1942 9 2 > > 1942-09-02 > > -----Original Message----- > From: Programming <[email protected]> On Behalf Of > Joe Bogner > Sent: Wednesday, April 4, 2018 16:56 > To: [email protected] > Subject: [Jprogramming] converting date number to iso 8601 > > I'm curious if there is a speedier way to convert a date stored as a > number like 20180101 or 20170228 to the ISO 8601 equivalent: > > This does OK > > datenumToISO =: 3 : 0 > (4&{. , '-' , 2&{.@(4&}.) , '-' , _2&{.)"1 ": y > ) > > datenumToISO 20180101 > 2018-01-01 > datenumToISO 20180228 > 2018-02-28 > > > But is slower than I'd like ... no big deal but just curious > > 6!:2 'datenumToISO (5e6 1 $ 20180102)' > 4.29083 > > sprintf is slow > > dateNumToISO2 =: 3 : 0 > '%d-%02d-%02d' sprintf ,:(0 100 100 #: y) > ) > > (6!:2) 'dateNumToISO2 (1e5 # 20180102)' > 2.34002 > (6!:2) 'dateNumToISO2 (1e6 # 20180102)' > 25.4977 > > > 8!:2 shows promise but I can't figure out the formatting string to add a > leading zero if it's possible > > (6!:2) '8!:2 (0 100 100 #: (5e6 # 20180102))' > 1.4853 > > 'q<->,q<->,d' 8!:2 (0 100 100 #: (1 # 20180102)) > 2018-1-2 > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
