How to get current datetime in SQL

0 votes

In order to add the current date and time to the lastModifiedTime column. I work with the MySQL database. My inquiries are:

  1. Does SQL have a function that is available? or
  2. Every database has a different method for this because it depends on the implementation, right?
  3. What is the function that MySQL offers?

 

Aug 30, 2022 in Database by Kithuzzz
• 38,000 points
1,560 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

1. Is there a function available in SQL?
Yes, the SQL 92 spec, Oct 97, pg. 171, section 6.16 specifies these functions:

CURRENT_TIME       Time of day at moment of evaluation
CURRENT_DATE       Date at moment of evaluation
CURRENT_TIMESTAMP  Date & Time at moment of evaluation

2. It is implementation depended so each database has its own function for this.

Each database has its own implementations, but if they adhere to the SQL 92 specification, it must implement the three functions mentioned above (but depends on the version of the spec)

3. What is the function available in MySQL?

NOW() returns 2009-08-05 15:13:00  
CURDATE() returns 2009-08-05  
CURTIME() returns 15:13:00  

I hope this helps you.

answered Aug 31, 2022 by narikkadan
• 86,360 points

edited Mar 5
0 votes
SELECT  (SYSDATE)

FROM DUAL;
answered Sep 19, 2023 by anonymous

edited Mar 5

Related Questions In Database