Jump to content

Date Range Query


dweb

Recommended Posts

Hi

 

I need to run a query that does a date range search.

 

My dates are stored as the following format

 

Fri Jan 05 2014

 

I know how to run a query when the dates are stored as YYYY-MM-DD but I cannot figure out how to run a query with the format my dates are stored in

 

I can't change the format of the fields as it's part of a bigger system

 

Does anyone have any suggestions?

Link to comment
Share on other sites

You can use STR_TO_DATE() to convert that useless format of yours into the correct yyyy-mm-dd format

... WHERE STR_TO_DATE(mydate, '%a %b %d %Y') BETWEEN d1 AND d2

d1 and d2 should be in yyyy-mm-dd format

 

EG

mysql> SELECT STR_TO_DATE('Fri Jan 05 2014', '%a %b %d %Y') as date;
+------------+
| date       |
+------------+
| 2014-01-05 |
+------------+
Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.