/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function get_rangeof_dates($time_frame= 'all_time') { $from_date= ''; $to_date= ''; switch($time_frame) { case 'all_time' : $from_date= '1170-01-01 00:00:00'; $to_date= '2250-12-31 23:59:59'; break; case 'today' : break; case 'yesterday' : break; case 'this_week' : break; case 'last_week' : break; case 'last_7_days' : break; case 'this_month' : break; case 'last_month' : break; case 'last_30_days' : break; case 'this_quarter' : if($month == 1 || $month == 2 || $month == 3) { $from_date= $year . '-01-01'; $to_date= $year . '-03-31'; } elseif($month == 4 || $month == 5 || $month == 6) { $from_date= $year . '-04-01'; $to_date= $year . '-06-30'; } elseif($month == 7 || $month == 8 || $month == 9) { $from_date= $year . '-07-01'; $to_date= $year . '-09-30'; } else { $from_date= $year . '-10-01'; $to_date= $year . '-12-31'; } break; case 'last_quarter' : if($month == 1 || $month == 2 || $month == 3) { $from_date=($year -1) . '-10-01'; $to_date=($year -1) . '-12-31'; } elseif($month == 4 || $month == 5 || $month == 6) { $from_date= $year . '-01-01'; $to_date= $year . '-03-31'; } elseif($month == 7 || $month == 8 || $month == 9) { $from_date= $year . '-04-01'; $to_date= $year . '-06-30'; } else { $from_date= $year . '-07-01'; $to_date= $year . '-09-30'; } break; case 'this_year' : break; case 'last_year' : break; } } ?>
URL: http://www.sajithmr.me/algorithm-for-range-of-dates/