In my form, I need to enter a date of purchase, I enter it in this format: DD/MM/YYYY (ie. 15/07/2019).
This field is a Mongo Date field.
But, when I enter this date : 01/02/2015, instead of : "2015-02-01T00:00:00.000+00:00", it saves "2015-01-31T23:00:00.000+00:00".
This is a problem because when I query and reorder the purchases by month, this purchase appears in January instead of February.
Maybe this is a Time zone problem but I think there is no way to change the default UTC Time zone in Mongo.
If so, I'm wondering what is the logic I should adopt in my controller?
UPDATE
I may have found a solution:
On my controller, before storing the date in the collection:
$string = '01/02/2015';
$datetime = DateTime::createFromFormat('j/m/Y', $string, new DateTimeZone('UTC'));
$datetime->setTime(00, 00, 00);
echo $datetime->format(DateTime::RFC3339_EXTENDED);
// Result: 2015-02-01T00:00:00.000+00:00
Then I store the result in the collection.
This is probably way too much, but is there a better solution?