I have a field in my MySQL database containing a date with a timezone that has the following format: 1986-07-10T00:00:00.000+02:00 or 1986-07-10T00:00:00.000Z (Z meaning zulu time, or UTC).
I am trying to compose a WHERE clause that checks if the difference between NOW (my timezone = Europe/Brussels) and the date field is more than e.g. 18 years. Is there any way I can accomplish this using only SQL?
I was reading about a function called CONVERT_TZ() but I’m not sure i’m going in the right direction.
to convert the time to your timezone, you could do somthing like:
Note from mysql manual
To use named time zones such as ‘MET’ or ‘Europe/Moscow’, the time zone tables must be properly set up. See Section 10.6, “MySQL Server Time Zone Support”, for instructions
Update exemple
if the table contains:
SELECT * FROM so_peter;
the result of this query is: