ChrisMartino Posted May 18, 2010 Share Posted May 18, 2010 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 :/ Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/ Share on other sites More sharing options...
Adam Posted May 18, 2010 Share Posted May 18, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060149 Share on other sites More sharing options...
ale8oneboy Posted May 18, 2010 Share Posted May 18, 2010 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."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060154 Share on other sites More sharing options...
ChrisMartino Posted May 18, 2010 Author Share Posted May 18, 2010 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060268 Share on other sites More sharing options...
Adam Posted May 18, 2010 Share Posted May 18, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060271 Share on other sites More sharing options...
ChrisMartino Posted May 18, 2010 Author Share Posted May 18, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060308 Share on other sites More sharing options...
Adam Posted May 18, 2010 Share Posted May 18, 2010 You wouldn't use an IF, you'd just use a WHERE clause within your query to only match records with that date. What exactly is it you're trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060314 Share on other sites More sharing options...
sharp.mac Posted May 19, 2010 Share Posted May 19, 2010 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....??? Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060352 Share on other sites More sharing options...
ale8oneboy Posted May 19, 2010 Share Posted May 19, 2010 I agree. This would be better off done through a query. What are you trying to do with this script? Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060507 Share on other sites More sharing options...
Adam Posted May 19, 2010 Share Posted May 19, 2010 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")); Quote Link to comment https://forums.phpfreaks.com/topic/202174-time-help/#findComment-1060519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.