[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1501
  • Last Modified:

Mysql Query - using Date functions

Hi
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
-s-
0
socross
Asked:
socross
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you need to apply quotes around the date value:
SELECT * FROM invoices WHERE invoice_status = 'sent' AND invoice_date >= '2007-06-14'

resp:
SELECT * FROM invoices WHERE invoice_status = 'sent' AND invoice_date >= '2007-06-01' AND invoice_date < '2007-07-01'
0
 
socrossAuthor Commented:
great thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now