how to find calendar quarters of each year

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mastikhor
Forum Newbie
Posts: 12
Joined: Fri Nov 11, 2005 5:33 am

how to find calendar quarters of each year

Post 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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post 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
}
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Post 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']);
    }
}
mastikhor
Forum Newbie
Posts: 12
Joined: Fri Nov 11, 2005 5:33 am

Post 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)
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Post 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..
mastikhor
Forum Newbie
Posts: 12
Joined: Fri Nov 11, 2005 5:33 am

Post 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
mastikhor
Forum Newbie
Posts: 12
Joined: Fri Nov 11, 2005 5:33 am

Post 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;	
?>
Post Reply