-2

How can I get the first and last date of the current month within PHP? I need this for a code which accepts a date range which has this format here:

array( 'date_paid' => $date_min . '...' . $date_max );

I know that this is a small function but I'm not sure how to do this. I would appreciate a little help. Thanks guys!

Mr. Jo
  • 4,946
  • 6
  • 41
  • 100

2 Answers2

0

You can get relative formats of date to get the first and last days of the current month

$firstDay = new DateTime('first day of this month');
$lastDay  = new DateTime('last day of this month');

$result = array(
    'date_paid' => $firstDay->format('Y-m-d') . '...' . $lastDay->format('Y-m-d') 
);
Maksym Fedorov
  • 6,383
  • 2
  • 11
  • 31
-1
$firstDay = mktime(0,0,0, $month, 1, $year);
$lastDay = mktime(0,0,0, $month + 1, 0, $year);

$lastDay has 0 as the day which makes it the last day of the last month and thus $month + 1

JensV
  • 3,997
  • 2
  • 19
  • 43