I have JSON data as below: I need to convert that date or mongo_date
into utc timestamp, to analyse the data in hive as per timeline example per year, per month, per week using map reduce
{
"_id" : ObjectId("51ac77050e9edcdad271ce2d"),
"company" : null,
"date" : "19760224",
"mongo_date" : ISODate("1976-02-24T00:00:00Z")
Hive understands this format:
'yyyy-MM-dd HH:mm:ss.SSS'
.Use
unix_timestamp()
to convert to seconds passed from 1970-01-01, then usefrom_unixtime()
to convert to proper format:Result:
Update. This method is to remove
Z
and replaceT
with space usingregexp_replace
and convert to timestamp if necessary, without usingunix_timestamp()
, this will preserve milliseconds:Result: