Date and time

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Date and time

Post by shivam0101 »

Hello,

I have to send emails exactly 24 hours before an event occurs. The system then waits for 5 minutes then again checks is there any new event within next 24 hours.

I am stroing the event date in

Code: Select all

date('Y:m:d H:i:s');
format.

1. How to check the event if it is inbetween? i.e if the event is for 10:12 PM and the system check every 5 minutes

the event will never be equal as it will check once at 10:10 and again at 10:15

2. Should i have to convert

Code: Select all

date('Y:m:d H:i:s')
to

Code: Select all

time()
? to comparing?

If there is any better way of doing it, please let me know.

Thanks
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Post by N1gel »

Just off the top off my head

If you have both dates saved to php variables could just test them as dates

Code: Select all

if($event > $PreviousDate and $event < $CurrentDate)
{

}
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

First of all you are storing the time and date as 1 value.

Try seperating your date and time values.

Regarding your time checker, as you already know the times of the events, you could base your "checking" script relative to the event's time. So instead of checking every 5 minutes set a pre-determined time that the emails should be sent.

Using a pre-determined time will also save server load.

I hope this is clear?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Or, just check if the particular date has passed and, if it has, mail the notification and remove it from the queue. Keep it simple.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

But he wants to check for events 24hrs before they happen!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

aceconcepts wrote:But he wants to check for events 24hrs before they happen!
Yes, which would be the date to check against.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Do what ~ N1gel said.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply