0

Hy all..I have a table where I'm storing the date in the following format: 'YYYY-mm-dd 00-00-00'. Now I want to make a select statement and display all records where date is BETWEEN the dates i give. Like this:

$c=mysql_query("SELECT * FROM useri where data_creare_user BETWEEN '2012-06-01' AND '20120-06-05' "); $d=mysql_fetch_array($c); echo $d['nume']; 

I know that I have to convert somehow the date from the table but I can't seem to figure it out.Can you tell me hoe to display the records based on that select statement?

0

2 Answers 2

1

If your data_creare_user column is not in a suitable temporal data type data type, it should be. Then:

SELECT * FROM useri WHERE DATE(data_creare_user) BETWEEN '2012-06-01' AND '2012-06-05' 
Sign up to request clarification or add additional context in comments.

Comments

0

It sounds like you're using a VARCHAR to hold your dates as string. If you can change the schema, you might be better off using a DATE or DATETIME type. That said, MySQL provides the function STR_TO_DATE() to help with this. Your query would then look something like:

SELECT * FROM useri WHERE STR_TO_DATE(data_creare_user, '%Y-%m-%d %H-%i-%s') BETWEEN STR_TO_DATE('2012-06-01', '%Y-%m-%d') AND STR_TO_DATE('20120-06-05','%Y-%m-%d'); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.