0

I am saving current date in mongodb with new Date(), But it is storing the date with the current time like below:

ISODate("2018-12-04T13:34:03.510+05:30")

I want to save only the date with above format, but without timezone for comparison purpose. Please tell me how can i do this?

3 Answers3

2

You can use this package. This allows you to save dates in Mongo without having to worry about time zones shifting the date. https://www.npmjs.com/package/mongoose-dateonly

Nasir Khan
  • 753
  • 1
  • 9
  • 22
0

You can save the date in the format of epoch time. And you can perform all kind of range queries on it.

Abhimanyu
  • 2,710
  • 2
  • 25
  • 42
0
var date = new Date('2018-12-04T13:34:03.510+05:30')
var userTimezoneOffset = date.getTimezoneOffset() * 60000;
new Date(date.getTime() - userTimezoneOffset);