Jump to content

Select Query Between Two Dates


stublackett

Recommended Posts

Hi,

 

I'm just doing a bit of archiving news by Season for a Football Site.

 

Looking to archive the news per season and it falls between these dates : 01/01/09 and 30/06/09 The date is formatted in UK Date format.

 

I've got this at the moment :

SELECT *, DATE_FORMAT( date, '%d/%m/%y' )AS uk_date FROM news WHERE newstype = 'Match Report' AND date => '01-01-09 AND <= 31-06-09' ORDER BY nid DESC

 

But its just erroring out... Any help appreciated

Link to comment
https://forums.phpfreaks.com/topic/180398-select-query-between-two-dates/
Share on other sites

Hi

 

You are checking for a date that is >= '01-01-09 AND <= 31-06-09', and that string isn't a valid date.

 

However you probably should use BETWEEN, and also use the real format for dates.

 

SELECT *, DATE_FORMAT( date, '%d/%m/%y' )AS uk_date

FROM news

WHERE newstype = 'Match Report'

AND date BETWEEN '2009-01-01' AND '2009-06-31'

ORDER BY nid DESC

 

All the best

 

Keith

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.