In SQL, GETDATE function is used to return the current system date and time in default format of the SQL Server instance.
GETDATE( )
• It is a zero parameter function that means it doesn't accept any argument.
1. Let's assume we have a table named "[Employees]".
2. Let's assume you want to append a new column called [CurrentDateTime] to the [Employees] table, containing the current date and time.
3. Run below SQL statement :
SELECT *, GETDATE() AS CurrentDateTime FROM [Employees];
4. In above statement, GETDATE function retrieves the current date and time and display it as the result in a column named 'CurrentDateTime'.
Using this function in a select statement won't modify the [Employees] table directly, but it will only be reflected in the select statement's output.
Use the GETDATE() function in SQL by calling it in your query or statement.
The GETDATE() function returns a datetime datatype.
Retrieve today's date in SQL by simply calling the GETDATE() function.
The format of the GETDATE() function's output is typically in the format: YYYY-MM-DD HH:MM:SS.