PHP function to get first and last date of a month
- Article
- Comment
PHP function to get first and last date of a month. Some times we may need to get the first and last days of a month. For example, if we need to get a monthly transaction . we have the month name or its count. but we need to know the first and last date to do. So here i am giving you the small piece of code to get the first and last date of a month.
function kvcodes_date_month($month) { $start_date = date('Y-'.$month.'-01'); $end_date = date('Y-'.$month.'-t'); $result arr = array($start_date, $end_date); return $result_arr; }
and you can just access this function by passing the month count , say for example, if you need to give march month, just pass ” 3″ as the parameter. Just like the following one
$date_arr = kvcodes_date_month(3); print_r($date_arr);
here it will print the two dates. you can process any month here. Drop your comments, if you have any doubt and queries.