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

Reply via email to