If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Selecting records by date using DAYOFYEAR()

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-20-03, 12:53
rudybob23 rudybob23 is offline
Registered User
 
Join Date: Oct 2003
Posts: 1
Selecting records by date using DAYOFYEAR()

Hi,
I'm not very well versed in mySQL but I've found myself using it every now and then. I need to select all records that have a date value within the next two weeks. What I've currently got is this:

select DATE_FORMAT(date, '%m\/\%d\/\%y'), location, time, id, numFree from refugee_clinical WHERE DAYOFYEAR(date) BETWEEN DAYOFYEAR(CURRENT_DATE) and (DAYOFYEAR(CURRENT_DATE)+14) order by date;";

This works, but I don't think that it will return the proper results from December 18th until January 1st as (CURRENT_DATE)+14 is going to be returning values above 365. Is there any easy way to get around this problem or should I just redesign the select statement using a different function?

Thanks in advance for any help!

-rudy
Reply With Quote
  #2 (permalink)  
Old 10-21-03, 10:37
Mincer Mincer is offline
Registered User
 
Join Date: Sep 2003
Location: London
Posts: 56
This should do what you're after.

Code:
SELECT
    DATE_FORMAT( date, '%m\/\%d\/\%y' )
  , location
  , time
  , id
  , numFree
FROM
    refugee_clinical
WHERE
    TO_DAYS( date ) - TO_DAYS( CURDATE() ) BETWEEN 0 AND 13
ORDER BY
    date
Regards,

Matt.

BTW, I think your DATE_FORMAT() string is a bit messed up
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On