Pradeep
Pradeep

Reputation: 90

Retrieving date from mysql

I have mysql datatype as date, my date format in database is 20/1/2015. Now I wish to retrieve data using date.

For example:

SELECT * FROM Device_Count where Date='20/1/2015' 
GO

I am getting error like: Incorrect date value: '20/1/2015' for column 'Date' at row 1

Please find and post the status

Upvotes: 0

Views: 115

Answers (3)

jrarama
jrarama

Reputation: 904

Date is stored in MYSQL in the format of YYYY-mm-dd. Try this query:

SELECT * FROM Device_Count where Date='2015-01-20'
GO

Upvotes: 0

Ravinder Reddy
Ravinder Reddy

Reputation: 24012

MySQL's date format is yyyy-mm-dd

change your query as below and it should work, provided your Date column data type is date.

SELECT * FROM Device_Count where Date=STR_TO_DATE('20/1/2015', '%d/%m/%Y' )

Refer to Documentation: STR_TO_DATE(str,format)

Upvotes: 6

roeygol
roeygol

Reputation: 5048

Check your date format and compare it by the same format

Upvotes: 0

Related Questions