Date Functions (getPreviousMonth, getNextMonth, getMonthYearTimestamp, addZero)


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.