Can strtotime give me the beginning/end of a time period (month, etc)?

Is it possible to (easily) get the first second of the current month with strtotime? (Or the start of any month, even not the current one)? Similarly, is it possible to get the end of the month, or first of next month? (I found that ‘Next month’ adds 30 days to the considered time.)

In order to get the beginning of the month, I have been doing this, which seems convoluted (especially when I have a value for time before hand, already in the format of a unix timestamp, because I have to format into a common format before returning it to a unix timestamp):

$year_month = date('Y-m', time());
$beginning_of_month = strtotime($year_month);

Any less convoluted suggestions would be appreciated.

strtotime(date('Y-m-01 00:00'));
strtotime('2014-07-01 00:00');

Thanks for that. I guess I was trying to not have to rely on using the output of date() in strtotime, but hopefully on a (easy to read) string that I could put into strtotime to accomplish the same thing. But your suggestion is still a bit easier to read.

The second construction you offered is more in line with what I was aiming for and works well.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.