Saturday, 13 October 2018
get last day of month in cakephp
$month = 0;
if (!empty($this->request->query('month'))) {
$month = $this->request->query('month');
}
$year = 0;
if (!empty($this->request->query('year'))) {
$year = $this->request->query('year');
}
$strFromDate = "$year-$month-01 00:00:00";
//$fromDate = $fromDate = strtotime(date('Y-m-01 00:00:00'));;
$fromDate = strtotime($strFromDate);
if (empty($month)) {
$fromDate = 0;
}
$strLastDateOfMonth = "$year-$month-t 23:59:59";
$lastDate = new Time("last day of $year-$month");
$strLastDate = $lastDate->i18nFormat('yyyy-MM-dd 23:59:59');
$toDate = strtotime($strLastDate);
if ($toDate > strtotime('now')) {
$toDate = strtotime('now');
}
$dateDiff = date_diff(new \DateTime(date("m/d/Y h:i:s A T", $fromDate)), new \DateTime(date("m/d/Y h:i:s A T", $toDate)));
debug($dateDiff);
debug($dateDiff->days);
exit();
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment