Posted By

luman on 10/22/08


Tagged

time date


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

brent-man
jamesming
Scooter
not_skeletor
silentbob84


Datesdiff


 / Published in: PHP
 

  1. function datediff($date1,$date2,$format='d'){
  2. $difference = abs(strtotime($date2) - strtotime($date1));
  3. switch (strtolower($format)){
  4. case 'min':
  5. $days = round((($difference/60)),0);
  6. break;
  7. case 'h':
  8. $days = round((($difference/60)/60),0);
  9. break;
  10. case 'd':
  11. $days = round((($difference/60)/60)/24,0);
  12. break;
  13. case 'm':
  14. $days = round(((($difference/60)/60)/24)/30,0);
  15. break;
  16. case 'y':
  17. $days = round(((($difference/60)/60)/24)/365,0);
  18. break;
  19. }
  20.  
  21. return $days;
  22. }

Report this snippet  

You need to login to post a comment.