My webhost server and its mysql database are not synced to the same time. I need the current timestamp from the mysql database. Right now, I have a table that I update a timestamp when I need to get the time. Is there a function that I can get the current timestamp from the mysql database without using a table?
I want to avoid having to store a timestamp, calling to update it and then selecting it everytime I need the current mysql database time.
CodePudding user response:
Should be like this:
select now()
or
select current_timestamp
Plenty examples here
CodePudding user response:
There exists 3 different functions which returns needed value.
NOW()
Return the current date and time at which the SQL statement executes.
It have a lot of aliases: CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP, LOCALTIME(), LOCALTIME, LOCALTIMESTAMP, LOCALTIMESTAMP().
SYSDATE()
Return the current date and time at which the function itself executes.
UTC_TIMESTAMP()
Return the current UTC date and time.
All 3 functions have optional argument - fractional part length specificator. Allowed values from 0 to 6 which means the accuracy from a second till a microsecond.