0

I have the field datetime with DATETIME type in MySQL. In PHP script I set date begin and date end like this: 11/12/1999 and 11/12/2001. In my table datetime saved in the next format: 11.11.1888 00:00:00. How can I compare these dates?

Thanks.

3
  • 1
    Could you post a code sample that shows how you "set date begin and date end"? And why 1888? Commented Oct 6, 2010 at 6:48
  • It is an example numbers. What code? I am asking a code. Commented Oct 6, 2010 at 6:57
  • So your question is "How to find entries between a start date and an end date"? Commented Oct 6, 2010 at 7:03

2 Answers 2

1

It could be done more easly, but this is one way:

$begindate = strreplace($begindate,'/','.');
$enddate = strreplace($enddate,'/','.');

mysql_query("SELECT * FROM MyTable
WHERE dateField BETWEEN '$begindate 00:00:00' AND '$enddate 23:59:59'");
Sign up to request clarification or add additional context in comments.

Comments

1

should be something like

SELECT *, STR_TO_DATE(datetime,'%d.%m.%Y') as newdatetime
FROM table
WHERE newdatetime >= STR_TO_DATE('11/12/1999','%d/%m/%Y')
AND newdatetime <= STR_TO_DATE('11/12/2001','%d/%m/%Y');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.