Reputation: 63
I have a column in MySQL where date is a string (d/m/Y). when I try to get this table ordered by date I get an internal server error and nothing happens:
$pdo->prepare('SELECT IdOrder,Name,Lname,Phone,Date FROM ordenes WHERE Lname LIKE ? ORDER BY STR_TO_DATE(Date, '%d/%m/%Y') DESC LIMIT 50');
What am I doing wrong?
Upvotes: 0
Views: 65
Reputation: 1418
maybe this works
$pdo->prepare("SELECT IdOrder,Name,Lname,Phone,Date FROM ordenes WHERE Lname LIKE ? ORDER BY STR_TO_DATE(Date, '%d/%m/%Y') DESC LIMIT 50");
You are using single quotes both in query and date format so you get PHP error. Another way is using backslashs:
$pdo->prepare('SELECT IdOrder,Name,Lname,Phone,Date FROM ordenes WHERE Lname LIKE ? ORDER BY STR_TO_DATE(Date, \'%d/%m/%Y\') DESC LIMIT 50');
Upvotes: 1