Comparison Problem

Hi Group,

I have a script to remind me on certain days of things.

The script allows a date of the reminder to be set as well as the number
of days prior to the date to be reminded on via email.

I am new to php so be gentle with my code (lol)

Basically what I need to do is check the reminder date (called date in
my mysql table) against todays date (only the month and day as the year
is not used due to it going to be a year on year event) factoring in the
number of days (reminderdays) prior to the date you want reminded of.

My code for the check is as follows - all the values appear to be
correct but this never evaluates as true:

if (date("m",strtotime($mail[date])) == date("m") &&
date("d",strtotime($mail[date])-$mail[reminderdays]) == date("d"))

Please would some php guru point me in the right direction?

Many Thanks!!

R.
Reapes [ Sa, 21 Juli 2007 18:47 ] [ ID #1774960 ]

Re: Comparison Problem

..oO(Reapes)

>I have a script to remind me on certain days of things.
>
>The script allows a date of the reminder to be set as well as the number
>of days prior to the date to be reminded on via email.
>
>I am new to php so be gentle with my code (lol)
>
>Basically what I need to do is check the reminder date (called date in
>my mysql table) against todays date (only the month and day as the year
>is not used due to it going to be a year on year event) factoring in the
>number of days (reminderdays) prior to the date you want reminded of.

Let the database do it. Store the event dates in a DATE column. Then use
MySQL's date and time functions to return all events where the current
date is somewhere within the "reminding range".

Micha
Michael Fesser [ Sa, 21 Juli 2007 19:08 ] [ ID #1774961 ]

Re: Comparison Problem

Thanks Michael - how would I go about it ?

At the moment I am selecting all records which haven't been sent then
*trying* to check the explained dates and intervals.

R

Michael Fesser wrote:
> .oO(Reapes)
>
>> I have a script to remind me on certain days of things.
>>
>> The script allows a date of the reminder to be set as well as the number
>> of days prior to the date to be reminded on via email.
>>
>> I am new to php so be gentle with my code (lol)
>>
>> Basically what I need to do is check the reminder date (called date in
>> my mysql table) against todays date (only the month and day as the year
>> is not used due to it going to be a year on year event) factoring in the
>> number of days (reminderdays) prior to the date you want reminded of.
>
> Let the database do it. Store the event dates in a DATE column. Then use
> MySQL's date and time functions to return all events where the current
> date is somewhere within the "reminding range".
>
> Micha
Reapes [ Sa, 21 Juli 2007 20:39 ] [ ID #1774963 ]

Re: Comparison Problem

..oO(Reapes)

>Thanks Michael - how would I go about it ?
>
>At the moment I am selecting all records which haven't been sent then
>*trying* to check the explained dates and intervals.

Without knowing your database design and any special requirements - just
some general ideas:

Let's assume there are some special events each year, stored with their
date in a DATE colum in the database. Even if they happen every year,
the dates should be stored including a year (could be the year when the
event did happen for the first time, like the year of birth in case of a
birthday calendar for example). Additionally there might be a simple INT
UNSIGNED column, containing the number of days that we want to get
notified before the event.

Now, to get all events that are within their notification range, you
could do something like this:

* Map the event dates to the current year. This could be done by using
DATE_ADD() to add the difference between the current year and the
event's year to the event's date, e.g.

DATE_ADD(eventDate, INTERVAL YEAR(NOW())-YEAR(eventDate) YEAR)

It's a quick 'n dirty hack, but it works (of course there might be a
better way ...)

* After you got the dates of the events in the current year, use
DATE_SUB() to substract the number of days to get the dates when the
reminding should begin.

* Now all you have to do is to select all events where the current date
NOW() is somewhere between these two calculated dates:

SELECT eventTitle
FROM events
WHERE NOW() BETWEEN eventDate AND
DATE_SUB(
DATE_ADD(
eventDate,
INTERVAL YEAR(NOW())-YEAR(eventDate) YEAR),
INTERVAL remindMe DAY
)

Just a quick shot ... untested ...

Micha
Michael Fesser [ So, 22 Juli 2007 03:06 ] [ ID #1775484 ]

Re: Comparison Problem

Post removed (X-No-Archive: yes)
Notifier Deamon [ Mo, 23 Juli 2007 20:36 ] [ ID #1776279 ]
PHP » alt.php » Comparison Problem

Vorheriges Thema: Need a php script that posts to a newsgroup
Nächstes Thema: Here my project