wowdezign Posted January 5, 2010 Share Posted January 5, 2010 Hello all! I hope that someone has a code snippet laying around that might help me to achieve the results I am after. Here is what I have: I want to massage some data coming from the db to arrange it into this: Array ( [0] => 2010 // year of the reservation start [1] => 01 // month of the reservation_start [2] => Array ( [0] => 6 // first day of the reservation from reservation_start [1] => 7 // second day of the reservation from reservation_start [2] => 8 // third day of the reservation from reservation_start ) ) Now I have gotten the basics but I don't know what functions to use to account for month changes or year changes. Maybe someone has a function similar that I can edit to suit my formatting requirements. This is the method I currently have: private function add_date_array($row){ // [property_id] => 1 // [reservation_start] => 2010-03-12 17:32:12 // [reservation_end] => 2010-03-16 17:32:12 // [number_of_days] => 4 $y = Date('Y',strtotime($row->reservation_start)); $m = Date('m',strtotime($row->reservation_start)); $d = Date('d',strtotime($row->reservation_start)); $this->date_arrs[0] = $y; $this->date_arrs[1] = $m; $this->date_arrs[2] = array(); for($i=0;$i<$row->number_of_days;$i++){ $this->date_arrs[2][] = $d + $i; } echo"<pre>"; print_r($this->date_arrs); echo"</pre>"; die(); } Link to comment https://forums.phpfreaks.com/topic/187328-date-math/ Share on other sites More sharing options...
wowdezign Posted January 5, 2010 Author Share Posted January 5, 2010 Sorry, I should have probably started this in the Math area. My apologies. :-\ Link to comment https://forums.phpfreaks.com/topic/187328-date-math/#findComment-989190 Share on other sites More sharing options...
MatthewJ Posted January 5, 2010 Share Posted January 5, 2010 you can use strtotime on the dates and just add the amount of seconds per day (60 * 60 * 24 or 86400 whichever you like) and then format the date with date to put it back to the timestamp format. That should be pretty quick with something like. $var1 = $strtotime($timestamp); $var2 = $var1 + (60 * 60 * 24 * $numberofdays) Link to comment https://forums.phpfreaks.com/topic/187328-date-math/#findComment-989206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.