Advertisement
nlozovan

Untitled

May 2nd, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. function dateDiff ($d1, $d2, $d3) {
  2. // Return the number of days between the two dates:
  3.  
  4. /*days from now till the start of the event*/
  5. $diff_start_event = round((strtotime($d2)-$d1)/86400); /*86400 is 24h (1 day) in secconds*/
  6.  
  7. /*days from now till the end of the event*/
  8. $diff_end_event = round((strtotime($d3)-$d1)/86400); /*86400 is 24h (1 day) in secconds*/
  9. $date_format = get_option( 'date_format' );
  10. //date()
  11.  
  12. if($diff_start_event > 0 && $d2 != '' && strtotime($d2) > $d1) { /*future*/
  13. if (abs($diff_start_event) == 1) {
  14. return abs($diff_start_event) . ' ' . __('day left', 'cosmotheme'); //one day, singular
  15. } else {
  16. return abs($diff_start_event) . ' ' . __('days left', 'cosmotheme'); //more than one day, plural
  17. }
  18.  
  19. }else if( $diff_start_event <= 0 && $d2 != '' && $diff_end_event >= 0 && $d3 != ''){
  20. return __('Ongoing','cosmotheme');
  21. }elseif ($diff_start_event < 0 && $d2 != '' && ( ($diff_end_event < 0 && $d3 != '') || $d3 == '' ) ) {
  22. return __('Expired','cosmotheme');
  23. }else if($d2 == '' && $d3 != ''){
  24.  
  25. if($diff_end_event > 0){
  26. if ( abs($diff_end_event) == 1 ) {
  27. return abs($diff_end_event) . ' ' . __('day left', 'cosmotheme'); //one day, singular
  28. } else {
  29. return abs($diff_end_event) . ' ' . __('days left', 'cosmotheme'); //more than one day, plural
  30. }
  31.  
  32.  
  33. }elseif($diff_end_event == 0){
  34. return __('Ongoing','cosmotheme');
  35. }else{
  36. return __('Expired','cosmotheme');
  37. }
  38. }
  39.  
  40.  
  41. } // end function dateDiff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement