Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB's ISODate() vs. UNIX Timestamp

Tags:

Is there any sort of advantage (performance, indexes, size, etc) to storing dates in MongoDB as an ISODate() vs. storing as a regular UNIX timestamp?

like image 557
James Simpson Avatar asked Jun 13 '11 16:06

James Simpson


People also ask

How do I manually convert a date to a timestamp in Unix?

To easily convert UNIX timestamp to date in the . csv file, do the following: 1. =R2/86400000+DATE(1970,1,1), press Enter key.

What is ISO date format in MongoDB?

You can specify a particular date by passing an ISO-8601 date string with a year within the inclusive range 0 through 9999 to the new Date() constructor or the ISODate() function. These functions accept the following formats: new Date("<YYYY-mm-dd>") returns the ISODate with the specified date.

Does MongoDB store timestamp?

The MongoDB Date and Timestamp typesThe DATE type in MongoDB can store date and time values as a combined unit. The BSON Date type is a signed 64-bit integer representing the number of milliseconds since the Unix epoch (Jan 1, 1970).


1 Answers

The amount of overhead of a ISODate compared to a time_t is trivial compared to the advantages of the former.

An ISO 8601 format date is human readable, it can be used to express dates prior to January 1, 1970, and most importantly, it isn't prey to the Y2038 problem.

This last bit can't be stressed enough. In 1960, it seemed ludicrous that wasting an octet or two on a century number could yield any benefit as the turn of the century was impossibly far off. We know how wrong that turned out to be. The year 2038 will be here sooner than you expect, and time_t are already insufficient for representing – for example – the schedule of payments on a 30-year contract.

like image 181
msw Avatar answered Nov 02 '22 13:11

msw