www.webdeveloper.com
Results 1 to 3 of 3

Thread: MySQL Date range query

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    9

    MySQL Date range query

    Hi,

    I have a MySQL query to gather information for a few date ranges. The following query works well for the current month, but things need to change a little, as it is not exactly what I require.

    Code:
    SELECT * FROM TABLE
    	WHERE YEAR(date_added) = YEAR(CURDATE())
    	AND MONTH(date_added) = MONTH(CURDATE())
    Here is the scenario...

    Staff get paid on the last FRIDAY of every month.
    The commission cut off date is the FRIDAY before the last Friday.
    The week Staff get paid gets added onto the following months information.

    I need to somehow be able to select this information via the date_added field.... complex i know!

    So i think it needs to be something like...

    FIND values BETWEEN the
    PREVIOUS months last week
    AND
    SECOND last Friday of the CURRENT MONTH.

    Can anyone whom knows MYSQL help me figure this one out?

    Regards,

    h4x

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,401
    I'd probably tackle the date determination in the application code (such as with a combination of PHP strtotime() and date() functions) to come up with the values to stick into the SQL in a BETWEEN statement. Is that feasible in your case, or do you have to do it in the SQL?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    This is an example which you van use to select the information between any date range.
    Select *
    from info_column
    where From_date
    between '2014-01-01' and '2014-01-31'

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles