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

Source: Internet
Author: User
Php date function example: get the last day of the month

  1. /**
  2. * Date-get the last day of the current 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. }

For example, the php date function calculates the difference between two dates.

  1. /**
  2. * Php date-calculate the difference between two 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. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.