Home > Backend Development > PHP Tutorial > PHP date function example: get the last day of the month

PHP date function example: get the last day of the month

WBOY
Release: 2016-07-25 08:51:48
Original
880 people have browsed it
  1. /**
  2. * Date-get the last day of the month
  3. * @return int
  4. */
  5. public function get_lastday() {
  6. if($this->month==2) {
  7. $lastday = $this->is_leapyear($this-> year) ? 29 : 28;
  8. } elseif($this->month==4 || $this->month==6 || $this->month==9 || $this->month ==11) {
  9. $lastday = 30;
  10. } else {
  11. $lastday = 31;
  12. }
  13. return $lastday;
  14. }
  15. /**
  16. * php date - whether it is a leap year
  17. * @return int
  18. */
  19. public function is_leapyear($year) {
  20. return date('L', $year);
  21. }
Copy code

Example, PHP date function to calculate the difference between two dates

  1. /**
  2. * php date-calculate the difference between 2 dates
  3. * @return int
  4. */
  5. public function get_difference($date, $new_date) {
  6. $date = strtotime($date);
  7. $new_date = strtotime($new_date);
  8. return abs( ceil(($date - $new_date)/86400));
  9. }
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template