×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Eray Demirel
Added: Nov 18, 2016 1:51 PM
Views: 16
Set day number of given DateTime object
  1. function set_day($daynum,  DateTime $object){
  2.     $obj= clone $object;
  3.     $lastdayofmonth=$obj->format("t")*1;
  4.     $day=$obj->format("j")*1;
  5.    
  6.     if($daynum>$lastdayofmonth){$daynum=$lastdayofmonth;}
  7.    
  8.     $obj->modify(($daynum-$day)." days");
  9.     return $obj;
  10. }