SHARE
TWEET

Untitled

a guest Jun 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php    
  2. $d = array();
  3. for($i = 0; $i < 30; $i++)
  4.     $d[] = date("d", strtotime('-'. $i .' days'));
  5. ?>
  6.      
  7. for ($i = 0; $i < 30; $i++)
  8. {
  9.     $timestamp = time();
  10.     $tm = 86400 * $i; // 60 * 60 * 24 = 86400 = 1 day in seconds
  11.     $tm = $timestamp - $tm;
  12.  
  13.     $the_date = date("m/d/Y", $tm);
  14. }
  15.      
  16. $d = array();
  17. for($i = 0; $i < 30; $i++)
  18.     array_unshift($d,strtotime('-'. $i .' days'));
  19.      
  20. $sales = Sale::find_all();//the sales object or array
  21.  
  22.   for($i=0; $i<7; $i++){
  23.     $sale_sum = 0;  //sum of sale initial
  24.     if($i==0){
  25.     $day = strtotime("today");
  26.   } else {
  27.    $day = strtotime("$i days ago");
  28.   }
  29.   $thisDayInWords = strftime("%A", $day);
  30.  
  31.   foreach($sales as $sale){
  32.     $date = strtotime($sale->date_of_sale)); //May 30th 2018 10:00:00 AM
  33.     $dateInWords = strftime("%A", $date);
  34.  
  35.     if($dateInWords == $thisDayInWords){
  36.         $sale_sum += $sale->total_sale;//add only sales of this date... or whatever
  37.     }
  38.   }
  39.   //display the results of each day's sale
  40.   echo $thisDayInWords."-".$sale_sum; ?>
  41.  
  42.  }
  43.      
  44. $today     = new DateTime(); // today
  45. $begin     = $today->sub(new DateInterval('P30D')); //created 30 days interval back
  46. $end       = new DateTime();
  47. $end       = $end->modify('+1 day'); // interval generates upto last day
  48. $interval  = new DateInterval('P1D'); // 1d interval range
  49. $daterange = new DatePeriod($begin, $interval, $end); // it always runs forwards in date
  50. foreach ($daterange as $date) { // date object
  51.     $d[] = $date->format("Y-m-d"); // your date
  52. }
  53. print_r($d);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top