Forum Moderators: coopster

Message Too Old, No Replies

Working the dates

The closest entry to today date

         

jacktheripper

12:51 pm on Feb 23, 2004 (gmt 0)

10+ Year Member



Hi, I am new to WebmasterWorld so, nice to meet you!

I am working on a calendar in php.

On the calendar table, i need to find the entry with che closest day to the actual day, of course avoiding dates in the past.

I am exploring all the built-in mysql functions but I have not found anything yet.

Can anyone help me?

webadept

3:45 pm on Feb 23, 2004 (gmt 0)

10+ Year Member



This page will probably help you out with most of your questions.

[faqts.com...]

webadept

4:11 pm on Feb 23, 2004 (gmt 0)

10+ Year Member



oh.. sorry, tired, didn't see that 'mysql' thing in there.. these should hook you up:

DAYNAME( date)
Returns the name of the day of the week for the given date (e.g., DAYNAME('1998-08-22') returns "Saturday").

DAYOFMONTH( date)
Returns the day of the month for the given date (e.g., DAYOFMONTH('1998-08-22') returns "22").

DAYOFWEEK( date)
Returns the number of the day of the week (1 is Sunday) for the given date (e.g., DAY_OF_WEEK('1998-08-22') returns "7").

DAYOFYEAR( date)
Returns the day of the year for the given date (e.g., DAYOFYEAR('1983-02-15') returns "46").

Glenn Hefley

lorax

6:02 pm on Feb 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why not set your WHERE clause to only include dates after the target date. Then use ORDER BY to sort the dates in ascending order. Use LIMIT to get just one record - the first record returned should be the next date right?

jacktheripper

4:41 pm on Feb 24, 2004 (gmt 0)

10+ Year Member



Hi!

Tnx for yours replies! :)

I came to this:

SELECT * FROM cms_calendar
WHERE cal_date >= TO_DAYS(NOW()) ORDER BY cms_calendar.cal_date ASC LIMIT 0,1

It works... without taking consideration of the actual date... really I do not know what to do now!

jacktheripper

3:15 pm on Mar 1, 2004 (gmt 0)

10+ Year Member



ops... that's the correct way

WHERE cal_date >= CURDATE

:)