Reputation: 1623
I have following data:
Array
(
[month] => 07
[year] => 2014
)
I want start & end timestamp of july 2014 using above array.
Upvotes: 0
Views: 157
Reputation: 7447
Perhaps something like this:
$start_month_str = $array['year'] . '-' . $array['month'] . '-1 midnight';
$end_month_str = $start_month_str . ' + 1 month - 1 minute';
$start_month_stamp = strtotime($start_month_str);
$end_month_stamp = strtotime($end_month_str);
http://php.net/manual/en/function.strtotime.php
Upvotes: 1
Reputation: 586
Used functions: http://php.net//manual/ru/function.cal-days-in-month.php http://php.net/manual/ru/function.mktime.php
<?php
$array = array('Month' => 07, 'Year' => 2014);
$daysCount = cal_days_in_month(CAL_GREGORIAN, $array['Month'], $array['Year']); //obtain month days count
$firstDay = mktime(0, 0, 0, $array['Month'], 1, $array['Year']); //obtain timestamp of specified month first day
$lastDay = mktime(0, 0, 0, $array['Month'], $daysCount, $array['Year']); //obtain timestamp of specified month last day
echo 'First: '.$firstDay.' Last: '.$lastDay;
?>
Upvotes: 1