Hello
I’m starting with functions and SQL / MySQL programming in LibreOffice Base, and I’m having some little problems to create my first programs. I need a bit of help with structure, notation, etc.
Well right now I have a table and in that table I have a field with the employee DOB (Date of Born), that field is in Spanish sorry, and it is: “FechaNac”
Then, I have other field that retrieve the current system date. I do that with the MySQL function CURDATE()
In SQL I type… CURDATE( ) “FechaActual”
That introduce the current system date in the field “FechaActual”
Perfect.
Now what I want is to obtain the difference in days between the date of born (DOB) “FechaNac” and the current system date “FechaActual”
For that purpose we have a function called DATEDIFF()
However, I’m typing this…
DATEDIFF(“FechaActual”,“FechaNac”) AS Anos
And that give me a syntax error so I’m doing something wrong…
This is my piece of code:
SELECT
“Nombre”,
“Apellido1ero”,
“Apellido2seg”,
“Sexo”,
“FechaNac”,
CURDATE( ) “FechaActual”
DATEDIFF(“FechaActual”,“FechaNac”) AS Anos
FROM “tbl_EMPLEADOS”
Reference for DATEDIFF() can be found here
http://www.w3schools.com/sql/func_datediff_mysql.asp
What I want to do is finding the days of difference between “FechaActual” and “FechaNac”.
Having that information, I can divide the days of difference between both dates by 365 and then calculating the employee’s years having it’s DOB and the current system date.
However, I don’t know how to use well DATEDIFF() and I am getting that error…
What am I doing wrong?
Any help would be really appreciated
Cheers