Wouter
Wouter

Reputation: 495

PHP Only got month need whole timestamp

I've got a month number from an array and put it in a variable.
Now i want to use the month to make the whole datestamp at the beginning or ending of the month.
But for the life of me, I can't figure out how to do that.

$startmonth = date("m", strtotime($date[1]));

$endmonth= date("m", strtotime($date[3]));

The startdate variable should be something like this: 2015-06-01
The enddate variable should be something like this: 2015-07-30

Upvotes: 0

Views: 29

Answers (1)

CodeBoy
CodeBoy

Reputation: 3300

$startmonth = date("Y-m-01", strtotime($date[1]));
$endmonth = date("Y-m-d", strtotime("last day of this month", strtotime($date[3])));

First of month is easy: it is always "01" so code that in your format.

Last day of month is harder. Fortunately PHP's strtotime allows for a lot of date manipulations. See doc at HERE.

Upvotes: 1

Related Questions