GETDATE

The SQL GETDATE function is a built-in date and time function in SQL Server that returns the current date and time of the system. It is a non-deterministic function, meaning that it returns a different value every time it is called, depending on the current system time.

Syntax

The syntax for the GETDATE function is simple. You can use it without any arguments, like this:

SELECT GETDATE();

This will return the current date and time in the default format, which is yyyy-mm-dd hh:mi:ss.mmm (year-month-day hour:minute:second.millisecond).

Example

You can also use the GETDATE function as part of other SQL statements. For example, you might use it to insert the current date and time into a table:

INSERT INTO MyTable (MyColumn, MyDate) 
VALUES ('Some data', GETDATE());

This would insert a row into MyTable, with the current date and time in the MyDate column.

In addition to GETDATE, SQL Server provides several other built-in date and time functions, such as DATEADD, DATEDIFF, and DATEPART, which can be used for a variety of date and time manipulation tasks. By using these functions in combination with GETDATE, you can perform a wide range of operations on dates and times in your SQL queries.