Home:ALL Converter>UNIX_TIMESTAMP() repeated more than once in MySQL request

UNIX_TIMESTAMP() repeated more than once in MySQL request

Ask Time:2015-03-07T22:20:04         Author:cls

Json Formatter

I need to get current date (and time 00:00:00) epoch timestamp in MySQL request. I want to do this with math expression: (UNIX_TIMESTAMP() - (UNIX_TIMESTAMP() % 86400)).

But this calls UNIX_TIMESTAMP() more than once; so the question is - is there a possibility that two UNIX_TIMESTAMP() functions return different time? What is the workaround in this case?

Or maybe MySQL executes UNIX_TIMESTAMP() once, and replaces all other calls with current timestamp and no workaround needed?

Author:cls,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28915848/unix-timestamp-repeated-more-than-once-in-mysql-request
Paul Dixon :

You could use UNIX_TIMESTAMP(NOW()), because NOW() returns the timestamp when the statement began to execute, so it would behave consistently across multiple calls in the same statement.\n\n\n NOW() returns a constant time that indicates the time at which the\n statement began to execute. (Within a stored function or trigger,\n NOW() returns the time at which the function or triggering statement\n began to execute.)\n",
2015-03-07T14:30:52
i486 :

SELECT @ut:=UNIX_TIMESTAMP(), (@ut - (@ut % 86400)) AS ep;\n",
2015-03-07T14:24:44
yy