Reputation: 8411
Date on remote server is GMT 0. Date on local machine is GMT +3. An item is getting inserted to DB on 00:30 on GMT +3. How to select this item in each timezone properly, so in GMT 0 it will be on x.month and GMT +3 it will be x+1.month?
I have tried this:
let n = new Date();
const todayStart = new Date(n.setHours(0, 0, 0, 0));
const todayEnd = new Date(n.setHours(23, 59, 59, 999));
// mongo query
date = {
$gte: desiredDateStart,
$lte: desiredDateEnd
};
This will be working if the server timezone matches the local's one. But if there is a gap, for 3 hours for example, the item will be selected only on requested for yesterday.
Upvotes: 1
Views: 30
Reputation: 125
Save the date to the DB using UTC and convert it to the specific timezone when retrieving it.
Upvotes: 1