954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Compare dates for CRONJOB

I have a CRON job set to run every hour (have to do it this often due to scheduling facilities on server) and one of the sections of the script is to check if a closing date for entries into an event is within 2 days and if so to email a reminder for payment to those who have not yet paid. When I tested it it seemed to work but a closing date is tomorrow and the emails didn't go out yesterday. I am looking for suggestions on how I can get this to work.

My current if statement is

if ($result['show_closing'] == date('Y-m-d', strtotime('+2 days'))) { // send email and updated the customer fes record to indicate that a reminder has been sent so it only does it once


The date is stored as date format in the database YYYY-MM-DD.

Any ideas please?

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

You could check if the date is <=

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Thank you, that has made me wonder whether I would be best doing a less than and greater than comparison - will have a play.

What about:

if ($result['show_closing'] > date('Y-m-d', strtotime('+1 days')) && $result['show_closing'] < date('Y-m-d', strtotime('+3 days'))) {


Would this work?

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

Yes that works. Less than 3 also means 2 days and 23 hours, if your column is a datetime. Not sure if that's what you want.

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Lets hope so - have yet to test it. I only have date for the column, not datetime as it is not required.

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

By the way this is all working now, thanks for the help

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: