How to mutate MongoDB _id?

How to mutate MongoDB _id to timestamp? It is possible to do on javascript ( new Date( parseInt( _id.toString().substring(0,8), 16 ) * 1000 ) ) but I can’t do it in mutation. Thank you!

Hi Andrew,
This one as calculation in mutate worked for me.

as.POSIXct(strtoi(str_sub(`_id`,1,8), base=16), origin="1970-01-01")

The resulting mutate command would be like this.

mutate(date_from_id = as.POSIXct(strtoi(str_sub(`_id`,1,8), base=16), origin="1970-01-01"))
1 Like

Thank you! It works!

1 Like