Jump to content

'time(); help.


ChrisMartino

Recommended Posts

Well with my company i have it so it puts the time stamp in the database like this:

 

$ExpireDate = time()+($CleanDays * 86400); // Add nummber of days to timestamp.

 

$CleanDays means either 30, 60 or 90.

 

Now if i put a PHP script on a cron tab how could i check if the timestamp is the date the script is run then if it is take action? e.g if the timestamp in the server's field in the database is the date it's set to expire how do i check that since i am really bad at timestamps :/

Link to comment
Share on other sites

Well to be honest you're not really using the right data type for that type of condition; I'd use 'date'. That way you only need to check if it's equal, and not within a range of seconds.

Link to comment
Share on other sites

Well to be honest you're not really using the right data type for that type of condition; I'd use 'date'. That way you only need to check if it's equal, and not within a range of seconds.

 

I agree with MrAdam. I was going to suggest the same. Using the date() function, convert the timestamp to just a date and compare the dates.

 

Lose Example:

 

<?php

//today
echo date("m/d/y")."<br><br>";

//April 1st 1971
echo date("m/d/y","39393992")."<br><br>";

//is today after April 1st 1971?
if(date("m/d/y","39393992") < date("m/d/y"))
{
echo "Today is after 04/01/71.";
}

?>

Link to comment
Share on other sites

Well to be honest you're not really using the right data type for that type of condition; I'd use 'date'. That way you only need to check if it's equal, and not within a range of seconds.

 

I agree with MrAdam. I was going to suggest the same. Using the date() function, convert the timestamp to just a date and compare the dates.

 

Lose Example:

 

<?php

//today
echo date("m/d/y")."<br><br>";

//April 1st 1971
echo date("m/d/y","39393992")."<br><br>";

//is today after April 1st 1971?
if(date("m/d/y","39393992") < date("m/d/y"))
{
echo "Today is after 04/01/71.";
}

?>

 

Thank you, How could i make the following statment add 30, 60 or 90 days onto the date?

 

echo date("m/d/y","39393992")."<br><br>";

Link to comment
Share on other sites

You can use strtotime in combination with date() to easily add a number of days:

 

$expire_date = date("m/d/y", strtotime("+30 days"));

 

Then you can use that within your WHERE clause, which should look something like:

 

where date_field = '{$expire_date}'

 

Assuming you've set-up `date_field` as "date" data type.

Link to comment
Share on other sites

You can use strtotime in combination with date() to easily add a number of days:

 

$expire_date = date("m/d/y", strtotime("+30 days"));

 

Then you can use that within your WHERE clause, which should look something like:

 

where date_field = '{$expire_date}'

 

Assuming you've set-up `date_field` as "date" data type.

 

Ok so i have put this in my script:

 

$ExpireDate = date("d/m/y", strtotime("+".$CleanDays." days"));

 

So what would i do in the if statement to check if the date is the one in the database?, I have the script running on a daily cron.

Link to comment
Share on other sites

sounds like he wants basically a countdown clock of some kind to kick a response on date change.

 

So if today is something I scheduled 60 days ago, on date change being today (automatically) it will notify me.

 

that or there is was too much incense burning in this room....???

Link to comment
Share on other sites

You can use strtotime in combination with date() to easily add a number of days:

 

$expire_date = date("m/d/y", strtotime("+30 days"));

 

Then you can use that within your WHERE clause, which should look something like:

 

where date_field = '{$expire_date}'

 

Assuming you've set-up `date_field` as "date" data type.

 

Actually, to correct myself, you'd need the date in "YYYY-MM-DD" format (as MySQL dates are):

 

$expire_date = date("Y-m-d", strtotime("+30 days"));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.