MongoDB Documentation, Release 3.0.4 Types Date The mongo shell provides various methods to return the date, either as a string or as a Date object: Internally, Date (page 180) objects are stored as a 64 bit integer representing the number of milliseconds since the Unix epoch (Jan 1, 1970), which results in a representable date range of about 290 millions years into the past and future. Return Date as a String To return the date as a string, use the Date() method, as in the following example: • Date() method which returns the current date as a string. • new Date() constructor which returns a Date object using the ISODate() wrapper. • ISODate() constructor which returns a Date object using the ISODate() wrapper. var myDateString = Date(); To print the value of the variable, type the variable name in the shell, as in the following: myDateString The result is the value of myDateString : Wed Dec 19 2012 01:03:25 GMT-0500 (EST) To verify the type, use the typeof operator, as in the following: typeof myDateString The operation returns string . Return Date The mongo shell wrap objects of Date type with the ISODate helper; however, the objects remain of type Date . The following example uses both the new Date() constructor and the ISODate() constructor to return Date objects. var myDate = new Date(); var myDateInitUsingISODateWrapper = ISODate(); You can use the new operator with the ISODate() constructor as well. To print the value of the variable, type the variable name in the shell, as in the following: myDate The result is the Date value of myDate wrapped in the ISODate() helper: ISODate("2012-12-19T06:01:17.171Z") To verify the type, use the instanceof operator, as in the following: myDate instanceof Date myDateInitUsingISODateWrapper instanceof Date The operation returns true for both. Chapter 5. Administration 268