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
how to find calendar quarters of each year
Moderator: General Moderators
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).
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
}- trukfixer
- Forum Contributor
- Posts: 174
- Joined: Fri May 21, 2004 3:14 pm
- Location: Miami, Florida, USA
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']);
}
}- trukfixer
- Forum Contributor
- Posts: 174
- Joined: Fri May 21, 2004 3:14 pm
- Location: Miami, Florida, USA
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..
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..
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?
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;
?>