Example #1
0
/**
 * @ingroup datetime_helper
 * Function to calculate the difference between two dates in months
 * @param string $date_of_birth			Date of the start date
 * @param string $date_today			Date to compare upto , if blank then use today's date.
 * @return int							Return the number of months between the two dates.
 */
function datetime_age_in_months($date_of_birth, $date_today = '')
{
    if (preg_match('/(\\d{4})-(\\d{2})-(\\d{2})/', $date_of_birth, $match) and $date_of_birth != '0000-00-00') {
        $dateOfBirthCal = array('year' => $match[1], 'month' => $match[2], 'day' => $match[3]);
        $today = datetime_today($date_today);
        $tim = strtotime($today);
        $todayCal = array('year' => date('Y', $tim), 'month' => date('m', $tim), 'day' => date('d', $tim));
        $todayMonths = $todayCal['year'] * 12 + ($todayCal['month'] - 1);
        $dateOfBirthMonths = $dateOfBirthCal['year'] * 12 + ($dateOfBirthCal['month'] - 1);
        return $todayMonths - $dateOfBirthMonths;
    }
    return 0;
}
Example #2
0
 public function toolbar_add()
 {
     $data = array('start_date' => datetime_today());
     $id = $this->schedule_model->add_row($data);
     redirect('admin/schedules/edit/' . $id);
 }