Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: stonysmithI split the code up here to allow some comments:
v = InputCol #pickup value from input column
v = v.replace(" ","/") #change space to slash
v = v.replace(":","/") #change colon to slash
v = v + "/0/0/0" #pad with extra fields for time if needed
s = v.split("/") #split into an array
year = s.getItem(2).long()
month = s.getItem(1).long()
day s.getItem(0).long()
d = date(year,month,day) #convert to date
hour = s.getItem(3).long()
minute = s.getItem(4).long()
second = s.getItem(5).long()
t = time(hour,minute,second) #convert to time
datestr = d.str()+" "+t.str() #convert back to string
emit *
emit datestr
=======================
It can also be expressed shorter:
s = split(InputCol.replace(" ","/").replace(":","/") + "/0/0/0","/") #split into an array
d = date(s.getItem(2).long(),s.getItem(1).long(),s.get Item(0).long())
t = time(s.getItem(3).long(),s.getItem(4).long(),s.get Item(5).long())
datestr = d.str()+" "+t.str() #convert back to string
=======================
If you want to use US dates, switch the month/day:
d = date(s.getItem(2).long(),s.getItem(0).long(),s.get Item(1).long()) #convert to date