0

Date before 1980 (SQL)

Please can somebody help me I dont understand why I cant filter date before 1.1.1980 it doesnt work The code is: SELECT Birthdaydate FROM Customers WHERE Birthdaydate < '1.1.1980';

16th Nov 2020, 11:28 PM
Kevin
Kevin - avatar
6 Antworten
+ 4
LOL... Apparently I'm not the only one who gets triggered with that date format. 😉 Your date format should be 'YYYY-MM-DD'. Try: SELECT Birthdaydate FROM Customers WHERE BirthdayDate < '1980-01-01' This also assumes that Birthdaydate is a DATETIME field.
17th Nov 2020, 2:17 AM
David Carroll
David Carroll - avatar
+ 3
Otherwise, you could try: SELECT Birthdaydate FROM Customers WHERE Convert(DATETIME, Birthdaydate) < '1980-01-01'
17th Nov 2020, 2:20 AM
David Carroll
David Carroll - avatar
+ 1
Unfortunately nothing worked, but still thank you
17th Nov 2020, 1:57 AM
Kevin
Kevin - avatar
0
Try with either one of these date values and tell me if any of them works. '1980-1-1' '1980/1/1' '198011' (Edit) I forgot the month and date must be 2 digits, so try David's suggestion 👍
17th Nov 2020, 12:48 AM
Ipang
0
I haven't used MySQL, but generally SQL date comparisons work better with explicit conversion to native date type. Try this: SELECT Birthdaydate FROM Customers WHERE Birthdaydate < STR_TO_DATE('1.1.1980', '%d.%m.%Y');
17th Nov 2020, 12:53 AM
Brian
Brian - avatar
0
One more idea: WHERE DATEDIFF(Birthdaydate, '1980-1-1') < 0
17th Nov 2020, 2:02 AM
Brian
Brian - avatar