Date before 1980 (SQL) | Sololearn: Learn to code for FREE!

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';

11/16/2020 11:28:56 PM

Kevin

6 Answers

New Answer

+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.

+3

Otherwise, you could try: SELECT Birthdaydate FROM Customers WHERE Convert(DATETIME, Birthdaydate) < '1980-01-01'

+1

Unfortunately nothing worked, but still thank you

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 👍

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');

0

One more idea: WHERE DATEDIFF(Birthdaydate, '1980-1-1') < 0