How would I go about finding the unix timestamp of midnight of the previous Wednesday? My only approach would be to get the day index and day number of today, and subtract the difference, but I can think of several scenarios where this would fail, for example, early in a month before a Wednesday has happened.
I guess, more concisely, how do I find the date of the previous Wednesday?
Any help would be appreciated.
00:00 is midnight at the beginning of a day, 24:00 is midnight at the end of a day. For simplicity however, most digital clocks skip 24:00 - declaring that midnight is the start of a new day. I.e. 8th of Feb 24:00 and 9th of Feb 00:00 is in practice the same point in time.
The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch.
Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC. One of the primary benefits of using Unix time is that it can be represented as an integer making it easier to parse and use across different systems.
What about strtotime
?
$timestamp = strtotime("last Wednesday");
var_dump($timestamp);
var_dump(date('Y-m-d H:i:s', $timestamp)); // to verify
And you get this output :
int 1247608800
string '2009-07-15 00:00:00' (length=19)
which is indeed last wednesday, midnight.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With