-1

I have a form with a date picker which allows the user to select only the month and year. Upon submitting the form The value it gets from the form is:

$the_Date = $_POST['month_Year'];
echo 'month date: '.$the_Date.'<br />';
// echos 'month date: July 2015' in this example

I need to use this to create 2 dates. I need the 1st of July and the 31st of July. I can create the 1st no problems using:

$first_Of_Month = date("Y-m-d",strtotime('1 '.$the_Date));

But I don't know how to create the $last_Of_Month seeing as not all months end on the 31st. Any help would be greatly appreciated

Akira Dawson
  • 1,247
  • 4
  • 21
  • 45

1 Answers1

1

When using date(), the value t returns the number of days in the month.

You can run $last_of_month = date("Y-m-t", strtotime($the_Date));

Qirel
  • 25,449
  • 7
  • 45
  • 62
  • it was the letter 't'. Didn't know it existed. Beauty!! Thanks heaps for that! – Akira Dawson Jul 29 '15 at 00:21
  • Happy to help! :) Please check the answer as correct if this is the solution you went with! Also, reading the documentation on PHP.net is often a good start (Google is also your friend!). – Qirel Jul 29 '15 at 00:26
  • I can accept in a few minutes. Yeah I did read the documentation, but only did a skim read haha! – Akira Dawson Jul 29 '15 at 00:27
  • We've all been there! Happened to me (with `date()`actually!) just yesterday. Cheers! – Qirel Jul 29 '15 at 00:29