The SQL NOW() function will return current date and time based on server system.
It is supported by MySQL, in MS SQL Server, the function getdate() will do the same thing, and in Oracle we can use SELECT SYSDATE FROM DUAL to get the current date and time.
SQL NOW() Syntax
SELECT NOW()
SQL NOW() Example
Table: Employees
EmployeeId | FirstName | LastName | Created |
---|---|---|---|
203 | Mazojys | Fxoj | 2010-11-10 10:15:16 AM |
204 | Jozzh | Lnanyo | 2010-12-18 11:08:23 AM |
205 | Syllauu | Dfaafk | 2011-03-05 02:14:10 PM |
We want to insert a new employee to the table:
INSERT INTO Employees(FirstName, LastName, Created) VALUES('Goood', 'Yofdae', NOW())
After inserted the new employee, the table Employees will have one more record:
EmployeeId | FirstName | LastName | Created |
---|---|---|---|
203 | Mazojys | Fxoj | 2010-11-10 10:15:16 AM |
204 | Jozzh | Lnanyo | 2010-12-18 11:08:23 AM |
205 | Syllauu | Dfaafk | 2011-03-05 02:14:10 PM |
206 | Goood | Yofdae | 2011-07-18 10:14:10 PM |