Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between SYSDATE(),NOW(),CURRENT_TIMESTAMP,CURRENT_TIMESTAMP() in MySQL? [closed]

Tags:

database

mysql

As per my knowledge,

SYSDATE(),
NOW(),
CURRENT_TIMESTAMP, and
CURRENT_TIMESTAMP() 

in MySQL are synonyms for one another. They all returns same value,then why MySQL provides all of them ? Are there different scenarios where I can use specific one of them ?

like image 573
Ravi Jiyani Avatar asked Feb 04 '15 06:02

Ravi Jiyani


People also ask

What is difference between Sysdate and now functions in MySQL?

NOW() returns a constant time that indicate's the time at which the statement began to exicute whereas SYSDATE () returns the time at which it exicute... OR in other words NOW ()shows query exicution time and SYSDATE() shows self exicution time..

What is the difference between now () and CURRENT_TIMESTAMP?

CURRENT_TIME and CURRENT_TIME() are synonyms for CURTIME() . CURRENT_TIMESTAMP and CURRENT_TIMESTAMP() are synonyms for NOW() . Returns the current time as a value in 'hh:mm:ss' or hhmmss format, depending on whether the function is used in string or numeric context. The value is expressed in the session time zone.

What is the difference between now () and Sysdate () functions?

NOW() returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger, NOW() returns the time at which the function or triggering statement began to execute.) This differs from the behavior for SYSDATE() , which returns the exact time at which it executes.

What is CURRENT_TIMESTAMP in MySQL?

MySQL CURRENT_TIMESTAMP() Function The CURRENT_TIMESTAMP() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS.


2 Answers

After reading http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_current-timestamp document, concluded that :

NOW() returns a constant time that indicates the time at which the statement began to execute. NOW() returns the time at which the function or triggering statement began to execute, but SYSDATE() returns the exact time at which it executes.

And CURRENT_TIMESTAMP, CURRENT_TIMESTAMP() are synonyms for NOW().

like image 51
Ravi Jiyani Avatar answered Sep 20 '22 18:09

Ravi Jiyani


They aren't all synonymous.

SYSDATE() is different than NOW(), in a significant way. As a demonstration:

SELECT NOW(), SYSDATE(), SLEEP(5), NOW(), SYSDATE()

The output might look like this:

2018-03-01 11:09:19   2018-03-01 11:09:19   0   2018-03-01 11:09:19   2018-03-01 11:09:24

So, yes, there are specific scenarios where you might want to use SYSDATE() rather than NOW().

MySQL does provides several functions that can return the same result

DATE(NOW()) vs. CURRDATE()

I suspect that this is large part due to a desire to make transition from other Relational DBMS easier, by more closely matching (where possible and appropriate) the function names and syntax used by Oracle, SQL Server, and so on.

like image 24
spencer7593 Avatar answered Sep 20 '22 18:09

spencer7593