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
https://forums.phpfreaks.com/topic/202174-time-help/
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
https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060154
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
https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060268
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
https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060271
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
https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060308
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
https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060519
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.