RE: [PHP-DB] Determine last quarter

2002-03-20 Thread Rankin, Randy

If anyone is interested, this is what I finally came up with. I'm not sure
how graceful it is, but it works ;) 

?

$quarter = ceil(date('n')/3);

if ($quarter = 1)
{
$period_first_day = date(Y-m-d,
mktime(0,0,0,10,1,date(Y)-1));
$period_last_day = date(Y-m-d,
mktime(0,0,0,12,31,date(Y)-1));
}

elseif ($quarter = 2)
{
$period_first_day = date(Y-m-d,
mktime(0,0,0,1,1,date(Y)));
$period_last_day = date(Y-m-d,
mktime(0,0,0,3,31,date(Y)));
}

elseif ($quarter = 3)
{
$period_first_day = date(Y-m-d,
mktime(0,0,0,4,1,date(Y)));
$period_last_day = date(Y-m-d,
mktime(0,0,0,6,30,date(Y)));
}

elseif ($quarter = 4)
{
$period_first_day = date(Y-m-d,
mktime(0,0,0,7,1,date(Y)));
$period_last_day = date(Y-m-d,
mktime(0,0,0,9,30,date(Y)));
}

echo Start of Period: $period_first_daybr;
echo End of Period: $period_last_day;

?


-Original Message-
From: Rankin, Randy [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 19, 2002 8:57 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Determine last quarter


Hello all,

Does anyone know how I might determine the start date and end date of the
previous calendar quarter based on today's date. For example, today is
2002-03-19, so the previous quarter start date would return 2001-10-01 and
the previous quarter end date would return 2001-12-31. I am trying to
determine these dates for a report that generates previous quarter sales
based on today (whatever 'today' might be). Hope that's clear. 

Thanks in advance,

Randy Rankin



[PHP-DB] Determine last quarter

2002-03-20 Thread Henry Hank


 If anyone is interested, this is what I finally came up with. I'm not sure
 how graceful it is, but it works ;) 

Here's another method... which can be condensed, but I left it expanded to
demonstrate what was going on.  The trick is finding the first day of the
*next* month, and getting the previous day  (
mktime(0,0,0,$start_month+3,0,$year) ), which is always the last day of the
previous month.

-Hank


?
$quarter = ceil(date('n')/3);
$last_quarter = ($quarter==1?4:$quarter-1);
$year =($last_quarter==4?date(Y)-1:date(Y));
$start_month = (($last_quarter-1)*3)+1;
$end_day = date(d,mktime(0,0,0,$start_month+3,0,$year));
echo Start Date:.date(Y-m-d,mktime(0,0,0,$start_month,1,$year)).\n;
echo End
Date:.date(Y-m-d,mktime(0,0,0,$start_month+2,$end_day,$year)).\n;
?





__
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Determine last quarter

2002-03-19 Thread Rankin, Randy

Hello all,

Does anyone know how I might determine the start date and end date of the
previous calendar quarter based on today's date. For example, today is
2002-03-19, so the previous quarter start date would return 2001-10-01 and
the previous quarter end date would return 2001-12-31. I am trying to
determine these dates for a report that generates previous quarter sales
based on today (whatever 'today' might be). Hope that's clear. 

Thanks in advance,

Randy Rankin