Select Date Query Between Date Range in MySQL

Query to  select data between 01-10-2011 and 31-10-2011

select * from table WHERE creation_date BETWEEN STR_TO_DATE('01-10-2011', '%d-%m-%Y') AND STR_TO_DATE('31-10-2011', '%d-%m-%Y')

Query to  select data between 01-11-2011 0900 hours and 02-11-2011 0800 hours

select * from table WHERE creation_date BETWEEN STR_TO_DATE('01-11-2011 09:00:00', '%d-%m-%Y %H:%i:%s') AND STR_TO_DATE('02-11-2011 08:00:00', '%d-%m-%Y %H:%i:%s')
Advertisements

2 thoughts on “Select Date Query Between Date Range in MySQL

  1. Note MySQL as many other databases (like MSSQL) understands the ISO format written “YYYY-MM-DD hh:mm:ss” without any other formatting information (I am not a fan of BETWEEN):

    select * from table WHERE creation_date >= ‘2011-10-01’ AND creation_date < '2011-11-01'

    There is no ambiguity as ISO format is preferred to all other ones.

    But your post is still interesting when you work with specific local settings and you want use them directly.

  2. Aw, it was quite a nice post. Around believed I wish to put in writing like that moreover ?§C spending time in addition to specific efforts to make a superb article?- however in order to I really say?- I really hesitate a lot and not just at all apparently go accomplished.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s