function dateDiff ($d1, $d2, $d3) { // Return the number of days between the two dates: /*days from now till the start of the event*/ $diff_start_event = round((strtotime($d2)-$d1)/86400); /*86400 is 24h (1 day) in secconds*/ /*days from now till the end of the event*/ $diff_end_event = round((strtotime($d3)-$d1)/86400); /*86400 is 24h (1 day) in secconds*/ $date_format = get_option( 'date_format' ); //date() if($diff_start_event > 0 && $d2 != '' && strtotime($d2) > $d1) { /*future*/ if (abs($diff_start_event) == 1) { return abs($diff_start_event) . ' ' . __('day left', 'cosmotheme'); //one day, singular } else { return abs($diff_start_event) . ' ' . __('days left', 'cosmotheme'); //more than one day, plural } }else if( $diff_start_event <= 0 && $d2 != '' && $diff_end_event >= 0 && $d3 != ''){ return __('Ongoing','cosmotheme'); }elseif ($diff_start_event < 0 && $d2 != '' && ( ($diff_end_event < 0 && $d3 != '') || $d3 == '' ) ) { return __('Expired','cosmotheme'); }else if($d2 == '' && $d3 != ''){ if($diff_end_event > 0){ if ( abs($diff_end_event) == 1 ) { return abs($diff_end_event) . ' ' . __('day left', 'cosmotheme'); //one day, singular } else { return abs($diff_end_event) . ' ' . __('days left', 'cosmotheme'); //more than one day, plural } }elseif($diff_end_event == 0){ return __('Ongoing','cosmotheme'); }else{ return __('Expired','cosmotheme'); } } } // end function dateDiff