mysql - Select between two dates dateformat -


maybe can me query. want select rows between 2 dates, i'm having problems date-format.

my query:

select id, number, date `table` (str_to_date(date, '%j-%n-%y') between '6-4-2015' , '6-4-2016') 

i don't know what's wrong query. i've tried use str_to_date , date.

the datetype of date text (and want keep it)

here's example of database:

1     233        5-4-2015 2     238        6-4-2015 3     431        7-4-2015 4     230        8-4-2015 

can me?

you doing wrong date conversion in str_to_date , looks dates in d-m-y format , doing as

mysql> select str_to_date('5-4-2015', '%j-%n-%y') ; +-------------------------------------+ | str_to_date('5-4-2015', '%j-%n-%y') | +-------------------------------------+ | null                                | +-------------------------------------+ 

so giving null , store ends there.

you should using

mysql> select str_to_date('5-4-2015', '%d-%m-%y') ; +-------------------------------------+ | str_to_date('5-4-2015', '%d-%m-%y') | +-------------------------------------+ | 2015-04-05                          | +-------------------------------------+ 1 row in set (0.00 sec) 

now comparison should as

where  str_to_date(date, '%d-%m-%y')  between  str_to_date('6-4-2015','%d-%m-%y') , str_to_date('6-4-2015','%d-%m-%y') 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -