Mysql Query - using Date functions

Posted on 2007-10-14
Last Modified: 2008-01-09
I need a bit of help getting a couple of db queries working which work with a date stored in a mysql database.

Query 1
This needs to pull out all rows where invoice_date is greater or equal than the provided date, below is my current attempt

SELECT * FROM invoices WHERE invoice_status = 'sent' AND invoice_date >= 2007-06-14

Query 2
This needs to pull out all rows where invoice_date is in a certain month (based on a YEAR and MONTH 10)

SELECT * FROM invoices WHERE invoice_status = 'sent' AND MONTH('invoice_date') = 10 AND YEAR('invoice_date') = 2007

ANy suggestions would be much appriciated

Many thanks
Question by:socross
    LVL 142

    Accepted Solution

    you need to apply quotes around the date value:
    SELECT * FROM invoices WHERE invoice_status = 'sent' AND invoice_date >= '2007-06-14'

    SELECT * FROM invoices WHERE invoice_status = 'sent' AND invoice_date >= '2007-06-01' AND invoice_date < '2007-07-01'
    LVL 1

    Author Comment

    great thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
    I have been using r1soft Continuous Data Protection ( for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now