Jump to content

[SOLVED] ordering dates that are closest to the current date


tallberg

Recommended Posts

Hi

Im trying to select events that coinced with a date. The date must be no more than 3 month aheaut. -- this is all working

 

Lastly i want it to order events whose eve_start_date are closest to the current date.

 

Ive tryed order by curdate() but that seems to make an approximation of the between dates.

 

This is what i got.

 

SELECT * FROM event WHERE date( "2008/2/8" ) BETWEEN eve_start_date AND eve_end_date AND eve_confirmed = 1 AND eve_start_date <= DATE_ADD( CURDATE() , INTERVAL + 3 MONTH ) ORDER BY eve_start_date

 

Thanks if anyone can help

Link to comment
Share on other sites

I believe

 

SELECT * FROM event WHERE date( "2008/2/8" ) BETWEEN eve_start_date AND eve_end_date

 

retieves records that have dates between this date.

 

"Approximation". What i mean is that "order by curdate()"  orders the records whose  eve_start_date AND  eve_end_date are closest to the current date not just the eve_start_date.

Link to comment
Share on other sites

I believe

 

SELECT * FROM event WHERE date( "2008/2/8" ) BETWEEN eve_start_date AND eve_end_date

 

retieves records that have dates between this date.

 

That's not a valid SQL date -- use 2008-02-08 as a string literal, not with the DATE() function.  The latter is for extracting the date component of the DATETIME column.

 

"Approximation". What i mean is that "order by curdate()"  orders the records whose  eve_start_date AND  eve_end_date are closest to the current date not just the .

ORDER BY CURDATE() will do nothing at all... ORDER BY eve_start_date will do as you say, it doesn't know anything about "closest".

Link to comment
Share on other sites

I think i know where you are going.

 

for this

 

SELECT DATEDIFF( eve_start_date, CURDATE( ) )

FROM `event`

 

I get

 

0

-19

43

-18

-17

-4

-19

89

89

 

so i suppose i need to be able to remove the minus signs so the number of days in the past and future are treated the same?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.