Warum führt die folgende Abfrage in MySQL zu einer Null für dieses timestampdiff()?Warum bekomme ich einen NULL für dieses timestampdiff()?
SELECT EndDate, /* EndDate is YEAR(4) datatype with value 2013 */
year('2015-01-01') a,
timestampdiff(YEAR, Year('2015-01-01'), EndDate) b
FROM table
Ergebnisse:
EndDate a b
2013 2015 NULL
Meine Vermutung wäre, weil 'YEAR' kein Date- oder Datetime-Datentyp ist. https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampdiff – Uueerdo
Ja. Ich habe es behoben, indem ich einen Monat/Tag angehängt habe und er sieht es als Datetime. SELECT EndDate, CONCAT (EndDate, '- 01-01') a, TIMESTAMPDIFF (YEAR, STR_TO_DATE ('2015.01.01', '% Y-% m-% d'), CONCAT (EndDate , '- 01-01')) d FROM tblboard' –