Php date function example: get the last day of the month
- /**
- * Date-get the last day of the current month
- * @ Return int
- */
- Public function get_lastday (){
- If ($ this-> month = 2 ){
- $ Lastday = $ this-> is_leapyear ($ this-> year )? 29: 28;
- } Elseif ($ this-> month = 4 | $ this-> month = 6 | $ this-> month = 9 | $ this-> month = 11) {
- $ Lastday = 30;
- } Else {
- $ Lastday = 31;
- }
- Return $ lastday;
- }
-
- /**
- * Php date-whether it is a leap year
- * @ Return int
- */
- Public function is_leapyear ($ year ){
- Return date ('L', $ year );
- }
For example, the php date function calculates the difference between two dates.
- /**
- * Php date-calculate the difference between two dates
- * @ Return int
- */
- Public function get_difference ($ date, $ new_date ){
- $ Date = strtotime ($ date );
- $ New_date = strtotime ($ new_date );
- Return abs (ceil ($ date-$ new_date)/86400 ));
- }
|