I want to get the date of last monday at 00:00:00 in a specific timezone. When I try this:
DrupalDateTime::createFromFormat('U', strtotime('last week monday'))->setTime(0, 0, 0)->setTimezone(new \DateTimeZone('America/New_York'))->render()
The result is:
2022-06-12 20:00:00 America/New_York
Which is actually Sunday at 10 PM.
How can I get it to return 2022-06-13 00:00:00 America/New_York
instead?
This "corrects" what I was seeing, but feels wrong:
date_default_timezone_set('America/New_York');
$from = DrupalDateTime::createFromFormat('U', strtotime('last week monday'))->getTimestamp();
$to = DrupalDateTime::createFromFormat('U', strtotime('last monday'))->getTimestamp();
This gives me:
June 13th, 2022 12:00 AM
June 20th, 2022 12:00 AM
Which is last week monday through last monday (this week). Is calling ->format() setting the timezone offset twice, perhaps?
If I format this timestamp using:
DrupalDateTime::createFromFormat('U', $returned_value)->format('F j, Y H:i:s e')
I get this on the screen:
June 13, 2022 04:00:00 +00:00
The server is in UTC time. I simply want the timestamp of a date, without offsets applied (but correctly formatted to the user).
Edit:
The objective is to query for entities in Drupal created in the last week (starting on Monday), at midnight (00:00:00) through the following Monday at midnight, in this specific timezone.