PHP - Getting The Next 2 Weeks In Php
I'm looking for a method that will return the date for the next 2 weeks in php.
I can pull the date but I'm not sure about adding to the date. Can anyone point me in the correct direction? Similar TutorialsHere is my code: <?php //input will be start date $startdate=0; function getMondays($day,$month,$year,$i,$end){ $x = 7; $add=0; for($i; $i<$end; $i++){ $add++; //This will get the first set of Mondays //store it inside an array //time stamp 11 pm GMT on date $array[$i] = date('U', mktime(0, 0, 0, $month, $day+$counter, $year)); //$firstDay = date('d/m/y', mktime(0, 0, 0, $month, 4+$counter, $year)); $counter = $x * $add; } return $array; } This gets the four weeks following the date set and store it in an array: $Weeks = getMondays(04,04,2011,0,5); Each slot is the equivalent of a week e.g. week 1, week 2, week 3, week 4,week 5 //perform equivilence test if($week1==$currentdate || $currentdate<=$week2){ //for all week 1 stick the following sentence echo "data for week 1"; } if($currentdate>$week2 && $currentdate<=$week3){ //for all week 2 stick the following sentence echo "data for week 2"; } if($currentdate>$week3 && $currentdate<=$week4){ //for all week 3 stick the following sentence echo "data for week 3"; } if($currentdate>$week4 && $currentdate<=$week5){ //for all week 4 stick the following sentence echo "data for week 3"; } if($currentdate==$week5){ //where d/m/y = the date on week 5. //will now become week 1 data getMondays(d,m,y,0,4); } Now depending on which week it is, a set data is displayed which is hardcoded. Now what I want to do is to reset the array on week 4 (for the new month), without the array being repopulated with the old date: $Weeks = getMondays(04,04,2011,0,4); everytime the script is run. How do I do this? I have the following code: Code: [Select] //DETERMINES ASL POLICY if ($perfRow['ASL']=='ToArrange'){ $ASLdate = $perfRow['startDateTime']; $ASLconfirm = strtotime($ASLdate-'21 days'); echo "<!--[ASL=ToARRANGE--><p>An ASL Interpreted performance of this event is offered on".date("l, F j",strtotime($perfRow['startDateTime']))." at ".date("g:i a",strtotime($perfRow['startDateTime'])).".<br />Please contact me by ".date("l, F j",strtotime($ASLconfirm))." to confirm this service.</p>"; }What I need is that if the ASL is "To be Arranged" there is a date that lists for $ASLconfirm that is three weeks prior to $ASLdate. The code above gives me the following: Quote An ASL Interpreted performance of this event is offered on Friday, September 28 at 7:30 pm. Please contact me by Wednesday, December 31 to confirm this service. As you can see from the output the December date is NOT three weeks prior to the September date. Where did I go wrong in my coding? So I'm calling in data from a DB where each record is associated with a (column) 'start_time', 'no_shows', 'cancelled', and 'attended' I want to go through the results of this SELECT and count the number of no shows, cancellations and attended on a WEEKLY basis (based on the start_time). How can I achieve this?
The user will provide a date range and the DB will select the records based on that date range. Now this date range will then have to be split by weeks and then get the count. I'm totally stuck on the counting by weeks part. This is what I have so far: // Multidimensional Array with [boolean][week #] $no_shows_weekly = [ 'no_show' => [], 'week' => [] ]; $cancelled_weekly = [ 'cancelled' => [], 'week' => [] ]; $attended_weekly = [ 'attended' => [], 'week' => [] ]; foreach($result as $r) { $start_time = new DateTime($r['start_time']); if($r['is_no_show'] == 0 && $r['is_cancelled'] == 0) { array_push($attended_weekly['attended'], 1); array_push($attended_weekly['week'], date_format($start_time, "W")); } else { array_push($attended_weekly['attended'], 0); array_push($attended_weekly['week'], date_format($start_time, "W")); } array_push($no_shows_weekly['no_show'], $r['is_no_show']); array_push($no_shows_weekly['week'], date_format($start_time, "W")); array_push($cancelled_weekly['cancelled'], $r['is_cancelled']); array_push($cancelled_weekly['week'], date_format($start_time, "W")); } echo json_encode(array( 'success'=> 1, 'msg'=> array( 'No Shows' => $no_shows_weekly, 'Cancellations' => $cancelled_weekly, 'Attendend' => $attended_weekly ) )); Any suggestions or help is greatly appreciated! |