CURRENT_TIMESTAMP Examples in SQL Server (T-SQL)

The CURRENT_TIMESTAMP function returns the current date and time as a datetime value. This value is derived from the operating system of the computer that the instance of SQL Server is running on.

This function is the ANSI SQL equivalent to the T-SQL GETDATE() function, so you can use whichever one you prefer. Note that both functions have a lower date range and a lower default fractional precision than the T-SQL SYSDATETIME() function (which returns a datetime2(7) value).

This article provides examples of the CURRENT_TIMESTAMP function, including how you can use it with other functions to return the value you’re interested in.

Continue reading

GETDATE() Examples in SQL Server (T-SQL)

The GETDATE() function returns the current date and time as a datetime value. This value is derived from the operating system of the computer that the instance of SQL Server is running on.

This article provides examples of the GETDATE() function, including how you can use it with other functions to return the value you’re interested in.

Continue reading

SYSDATETIME() Examples in SQL Server (T-SQL)

The SYSDATETIME() function returns the current date and time as a datetime2(7) value. This value is derived from the operating system of the computer that the instance of SQL Server is running on.

This article provides examples of the SYSDATETIME() function, including how you can use it with other functions to return the value you’re interested in.

Continue reading

DATETIME2FROMPARTS() Examples in SQL Server (T-SQL)

In SQL Server, the DATETIME2FROMPARTS() function works similar to the DATETIMEFROMPARTS() function, except that it accepts 8 arguments and returns a datetime2 value. The DATETIMEFROMPARTS() function on the other hand, accepts just 7 arguments and it returns a datetime value.

Basically, you provide all the date/time parts and this function will return a datetime2 value based on the parts you provide.

Continue reading

DATETIMEFROMPARTS() Examples in SQL Server (T-SQL)

In SQL Server, the DATETIMEFROMPARTS() function works just like the DATEFROMPARTS() function, except that it also returns the time portion of the date.

The DATETIMEFROMPARTS() function accepts seven arguments, each representing a different part of the date/time. The function then returns a datetime value from the given parts.

Continue reading

DATEFROMPARTS() Examples in SQL Server (T-SQL)

You can use the T-SQL DATEFROMPARTS() function in SQL Server to return a date value that maps to the date parts that you provide as integer expressions.

The way it works is, you provide three values (one for each of the year, month, and day values), and SQL Server will return a date value based on the values you provide.

Examples below.

Continue reading