date - how to decrease months in php? -


i want separate 4 quarter months current month.

$q1start = date('y-m-01',strtotime('-2 months')); $q1end = date('y-m-d');  $q2start = date('y-m-01',strtotime('-5 months')); $q2end = date('y-m-d',strtotime('-3 months'));  $q3start = date('y-m-01',strtotime('-8 months')); $q3end = date('y-m-t',strtotime('-6 months'));  $q4start = date('y-m-01',strtotime('-11 months')); $q4end = date('y-m-t',strtotime('-9 months')); 

but not showing exact date.

i want this.

2015-06-01 2015-08-31  2015-03-01 2015-05-31  2015-02-28 2014-12-01  2014-09-01 2014-11-30 

how decrease current month? thanks

since quarters should based on current month, it's easier start first day of month calculations.

$dayofmonth = date('d'); $firstdayofcurrentmonth = strtotime(sprintf('-%d days + 1 day midnight', $dayofmonth));  $q1start = date('y-m-d', strtotime('-2 months', $firstdayofcurrentmonth)); $q1end = date('y-m-d', strtotime('+1 month - 1 day', $firstdayofcurrentmonth));  $q2start = date('y-m-d', strtotime('-5 months', $firstdayofcurrentmonth)); $q2end = date('y-m-d', strtotime('-2 month - 1 day', $firstdayofcurrentmonth));  $q3start = date('y-m-d', strtotime('-8 months', $firstdayofcurrentmonth)); $q3end = date('y-m-d', strtotime('-5 month - 1 day', $firstdayofcurrentmonth));  $q4start = date('y-m-d', strtotime('-11 months', $firstdayofcurrentmonth)); $q4end = date('y-m-d', strtotime('-8 month - 1 day', $firstdayofcurrentmonth)); 

this sets variables expected values.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -