Hbug
Hbug

Reputation: 177

Get records from the current data

I need to list the records from the current day, in the db the date is in format 02/02/11

Database

09/01/11
13/01/11
18/02/11
19/02/11
20/02/11

...

Question: How to do using SQL command + PHP?

Current (working...)

$today = date("Y/m/d");

$sql = SELECT * FROM places WHERE STR_TO_DATE(data, '%d/%m/%y') >= '".$today."' ORDER BY DATE_FORMAT(data, '%d/%m/%y') ASC LIMIT 8";

But all records are listed

Upvotes: 0

Views: 117

Answers (1)

BrynJ
BrynJ

Reputation: 8382

I would strongly recommend updating your stored values to the standard MySQL date field type - this will greatly simplify any queries you write and enable you to use all the standard MySQL date and time functions.

You can follow the answer here Converting a date in MySQL from string field to find out how to convert your data.

Upvotes: 2

Related Questions