comparing dates in mongodb

前端 未结 1 2024
孤城傲影
孤城傲影 2021-01-23 22:49

A Meteor server code updates a Mongodb collection, dateField has value looking like this
ISODate(\"2016-11-19T00:00:00Z\")

The client sele

相关标签:
1条回答
  • 2021-01-23 23:23

    new Date(year, month, date) variant will have the date in current system time zone.

    The reason you comparison doesn't return any results is when you pass the date in your local system zone , the meteor does a conversion from local datetime to UTC datetime as Mongo DB datetimes are in UTC time. So your input date changes from Sat Nov 19 2016 00:00:00 GMT+1100 (AEDT) to Fri Nov 18, 2016 01:00:00 UTC.

    Considering user inputs date as UTC. You'll just need to parse the date explicitly as UTC.

    Try

    new Date(Date.UTC(2016, 11, 19, 0, 0, 0, 0)
    

    and pass this to the query.

    0 讨论(0)
提交回复
热议问题