Posted By

strangerstudios on 06/15/10


Tagged

calendar dates timestamp


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

karp13


Date Functions (getPreviousMonth, getNextMonth, getMonthYearTimestamp, addZero)


 / Published in: PHP
 

  1. //date functions
  2. function addZero($n, $zeroes = 1)
  3. {
  4. if($n < pow(10, $zeroes))
  5. $n = "0" . $n;
  6.  
  7. if($zeroes > 1)
  8. return addZero($n, $zeroes - 1);
  9. else
  10. return $n;
  11. }
  12.  
  13. function getPrevMonth($m)
  14. {
  15. $r = $m - 1;
  16. if($r == 0) $r = 12;
  17.  
  18. return addZero($r);
  19. }
  20.  
  21. function getNextMonth($m)
  22. {
  23. $r = $m + 1;
  24. if($r == 13) $r = 1;
  25.  
  26. return addZero($r);
  27. }
  28.  
  29. function getMonthYearTimestamp($m, $y)
  30. {
  31. return strtotime($y . "-" . $m . "-01");
  32. }

Report this snippet  

You need to login to post a comment.