This is a discussion on URGENT HELP NEEDED PLEASE! Selecting a date range without the year within the MySQL Database forums, part of the Database Forums category; Hi, I need to be able to select a range of dates between cretain months and days but without the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I need to be able to select a range of dates between cretain months and days but without the year, Something like : SELECT foobar FROM footable WHERE dates BETWEEN start_date_month_day AND end_date_month_day That will return all the results between those months and days regardless of the year. Any help would be appreciated. Thanks, paul. |
|
|||
|
macca wrote:
> Hi, > I need to be able to select a range of dates between cretain months > and days but without the year, > > Something like : > > SELECT foobar FROM footable WHERE dates BETWEEN start_date_month_day > AND end_date_month_day > > > That will return all the results between those months and days > regardless of the year. > > > Any help would be appreciated. > > Thanks, paul. Can the dates span year boundaries? |
|
|||
|
On 23 Apr, 22:29, macca <ptmcna...@googlemail.com> wrote:
> Yes. > > Ive figured it out now though thanks, i used > > WHERE (MONTH(dates) BETWEEN month1 AND month2) > > thanks anyway But does that work when month1 is November and month2 is January? Also you haven't included the day part? |
|
|||
|
Well i did, i just didnt show it here. The where clause of the query
is: WHERE (MONTH(PurchaseDate) BETWEEN #form.txtStartMonth# AND #form.txtEndMonth#) AND (DAYOFMONTH(PurchaseDate) BETWEEN #form.txtStartDay# AND #form.txtEndDay#) AND (YEAR(PurchaseDate) BETWEEN #form.txtStartYear# AND #form.txtEndYear#) ORDER BY PurchaseDate ASC With each of DAYOFMONTH,MONTH & YEAR only being concatenated to the where clause if the user sets one in the form But you are right.This does not work when month1 is November and month2 is January. I didnt even think of this suggestion appreciated... |
|
|||
|
macca wrote:
> Well i did, i just didnt show it here. The where clause of the query > is: > > > WHERE (MONTH(PurchaseDate) BETWEEN #form.txtStartMonth# AND > #form.txtEndMonth#) AND (DAYOFMONTH(PurchaseDate) BETWEEN > #form.txtStartDay# AND #form.txtEndDay#) AND (YEAR(PurchaseDate) > BETWEEN #form.txtStartYear# AND #form.txtEndYear#) ORDER BY > PurchaseDate ASC > > With each of DAYOFMONTH,MONTH & YEAR only being concatenated to the > where clause if the user sets one in the form > > > But you are right.This does not work when month1 is November and > month2 is January. I didnt even think of this > > > suggestion appreciated... > > Just check - if start month is > end month, ensure the purchase date is NOT between end month and start month. I'll leve the actual SQL up to you - but it's not much different than what you have :-) -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |