Want to get current datetime
to insert into lastModifiedTime
column. I am using MySQL
database. My questions are:
is there a function available in SQL? or
it is implementation depended so each database has its own function for this?
what is the function available in MySQL?
This question is related to
sql
database
current-time
I want my datetime, and I want it now()!
For MySQL, anyway.
For SQL Server use GetDate() or current_timestamp. You can format the result with the Convert(dataType,value,format). Tag your question with the correct Database Server.
NOW()
returns 2009-08-05 15:13:00
CURDATE()
returns 2009-08-05
CURTIME()
returns 15:13:00
SYSDATETIME() 2007-04-30 13:10:02.0474381
SYSDATETIMEOFFSET()2007-04-30 13:10:02.0474381 -07:00
SYSUTCDATETIME() 2007-04-30 20:10:02.0474381
CURRENT_TIMESTAMP 2007-04-30 13:10:02.047 +
GETDATE() 2007-04-30 13:10:02.047
GETUTCDATE() 2007-04-30 20:10:02.047
I guess NOW() doesn't work sometime and gives error 'NOW' is not a recognized built-in function name.
Hope it helps!!! Thank You. https://docs.microsoft.com/en-us/sql/t-sql/functions/getdate-transact-sql
I always just use NOW():
INSERT INTO table (lastModifiedTime) VALUES (NOW())
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_now
try this
SELECT CURTIME();
return 23:12:58
SELECT CURDATE();
return 2020-11-12
SELECT NOW();
return 2020-11-12 23:19:26
SELECT DAY(now());
return 12
SELECT DAYNAME(now());
return Thursday
Hope this would be helpful for you.
GETDATE()
or GETUTCDATE()
are now superseded by the richer SYSDATETIME
, SYSUTCDATETIME
, and SYSDATETIMEOFFSET
(in SQL 2008)ANSI
has ever declared anything, and so each manufacturer has their own.NOW()
Hope this helps...
Rob
Source: Stackoverflow.com