This might be fast : '-' 4 7 } 1 1 1 1 2 1 2 1 ": 10#.inv 20170209
2017-02-09 On Wed, Apr 4, 2018 at 6:04 PM, Raul Miller <[email protected]> wrote: > Here's one approach: > > DXP=: (8#1) j. (i.8)e.3 5 > daten28601=: DXP #!.'-'"1 ":@,. > > 6!:2 'daten28601 (5e6 1 $ 20180102)' > 0.659381 > > -- > Raul > > On Wed, Apr 4, 2018 at 5:56 PM, Joe Bogner <[email protected]> wrote: > > 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
