How to convert mongodb timestamp to date format

135 views
Skip to first unread message

Madabhattula Rajesh Kumar

unread,
Jun 12, 2018, 7:51:59 PM6/12/18
to mongodb-user
Hi,

I have a following timestamp which is returned from mongo database. How to convert this into Date fomat(%Y-%m-%d %H:%M:%S)

timestamps

43263.50444579861
43263.50789454861
43263.51139024306
43263.5148625
43263.51833471065
43263.52180701389
43263.525255659726
43263.528727881945
43263.53222354167
43263.535695810184

Regards,
Rajesh

Kevin Adistambha

unread,
Jun 25, 2018, 3:38:47 AM6/25/18
to mongodb-user

Hi

How did you generate the timestamps? It doesn’t look like a UNIX epoch or any standard time format.

MongoDB includes the Date type. Once you convert those timestamps to a Date type, you can use the aggregation framework’s $dateToString to convert the dates to your required format.

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages