Results 1 to 3 of 3

Thread: MySQL Date range query

  1. #1
    Join Date
    Nov 2006

    MySQL Date range query


    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.

    	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
    SECOND last Friday of the CURRENT MONTH.

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



  2. #2
    Join Date
    Aug 2004
    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?
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  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