Page 1 of 1

how to find calendar quarters of each year

Posted: Sat Nov 12, 2005 6:49 am
by mastikhor
For an application, I need to identify calendar quarters of each year.

So once the concerned manager logs in to the system, code should check the candidate joining date and compare with the current month. If its completion of a quarter, an email response should go to manager and inform to fill the form.

Bottom line is I need a php code which can calculate calendar quarters from joining date of candidate to the current month

Posted: Sat Nov 12, 2005 7:22 am
by mickd
use the time() function.

when the user joins, store it in a mysql database.

then when they login, check to see if the current time() is 1/4 of a year later(7884000seconds).

Code: Select all

if(($storedtime + 7884000) >= time()) {
// send email
}

Posted: Sat Nov 12, 2005 8:23 am
by trukfixer
or, if stored in a mysql database- let mysql do the work:)

Code: Select all

//assume $row_id is a numeric value - empy result set returns 0
//assume you've stored join date to database as mysql datetime (2005-01-01 11:22:33) 
$res = mysql_query("select row_id from tablename where join_date < date_sub(curdate(),interval 90 day)");
while($info = mysql_fetch_array($res))//assuming you may want more than just one row
{
    if($info['row_id'] > 0)
    {
           $action = notify_whomever_too_notify($info['row_id']);
    }
}

Posted: Sat Nov 12, 2005 11:57 am
by mastikhor
Thanks for the help

i also need to find what is the quarter no of which year. Because in my table i've quarter no and year no.

(On every quarter, some information saves in database along with quarter No and Year No. So it will help me to extract all quarters and year available in database)

Posted: Sat Nov 12, 2005 12:06 pm
by trukfixer
check the mysql manual for date_sub or date_add functions - if you have mysql5 , they have the QUARTER function ..

As an alternative, you can use date_sub as I showed you before, , get the curdate() and the joined_date and explode() whichever date on the - and take the [1]th array element and do like quarter = 1; if month > 3 , quarter = 2, if month > 6, quarter = 3, if month > 9 , quarter = 4 and you will have the quarter number of whichever month you are looking at...

really isnt that complex to do..

Posted: Sat Nov 12, 2005 2:58 pm
by mastikhor
I've checked the mysql function already but client's server doesn't have mysql 5.0 so for an alternative i've to go through PHP.

Btw..It will be helpful for me to understand if you can write a code...

I'll appreciate that

Posted: Sun Nov 13, 2005 11:15 pm
by mastikhor
Seems like an incorrect logic to me. According to the below code, its fetching all the results from database and its hard to rectify which quarter number for which candidate.

Can someone modify my code more?

Code: Select all

<?
$currMonth = date('m');

$res = mysql_query("select * from `users` where joiningDate < date_sub(curdate(),interval 90 day)); 
while($row = mysql_fetch_array($res)) 
{ 
    if($row['id'] > 0) 
    { 
           
		   if($currMonth > 1 && $currMonth < 3){
		   	$quarter = 1;
		   }else if($currMonth > 3 && $currMonth < 6){
		   	$quarter = 2;		   
		   }else if($currMonth > 6 && $currMonth < 9){
		   	$quarter = 3;		   
		   }else if($currMonth > 9 && $currMonth < 12){
		   	$quarter = 4;		   
		   }
		echo $row['id']."<br>";
    } 
}
		   echo "current quarter is ".$quarter;	
?>