I have a standard mysql timestamp in this format 2011-11-14 20:06:24 . This timestamp will be added whenever a new record is added to the table with the name lead.
I have two input fields for the user to enter from date and to date in dd/mm/yyyy format. Once the user enters both dates and press a button the values will be passsed to other field to get the records from the table lead which are inserted between the time range.
I tried the below query but its not working
SELECT DATE_FORMAT(added_on, '%d/%m/%Y') as date
FROM lead
WHERE added_on BETWEEN "10/11/2011" AND "14/11/2011"
Use standard format for dates, datetimes and timestamps:
'2011-11-14'and not'14/11/2011'.Use single quotes, not double quotes.
If
added_onis a timestamp, you should not useBETWEENor you’ll lose almost all records from the last day because'2011-11-14'will be converted to'2011-11-14 00:00:00'. Use this instead:or
You should read carefully the
MySQL docs: TIMESTAMP propertiespage for how timestamps are handled (and auto-inserted, updated) in MySQL and theMySQL docs: Timezone support.