Date and Time functions in Sql Server|SQL tutorials for beginners| Sql interview question and answer

Опубликовано: 05 Октябрь 2024
на канале: OrBit of the CodinG
66
4

date and time functions.
CURRENT_TIMESTAMP - This function is used to get the current date and time values without including the time zone offset.
GETDATE() - This function is used to get the system's current date and time on which the SQL Server is installed
GETUTCDATE() - This function is used to get the current UTC date and time values as an integer.
SYSUTCDATETIME -This function is used to get the system's current date and time value based on the UTC timestamp as an integer.

SELECT CURRENT_TIMESTAMP AS 'DateAndTime_CURRENT_TIMESTAMP';
SELECT GETDATE() AS 'DateAndTime_GETDATE';
SELECT GETUTCDATE() AS 'DateAndTimeUtc_GETUTCDATE';

ISDATE – returns int - Returns 1 if a valid datetime type and 0 if not
SELECT ISDATE(GETDATE()) AS 'IsDate';
SELECT ISDATE(NULL) AS 'IsDate';

DAY – returns an integer corresponding to the day specified
MONTH– returns an integer corresponding to the month specified
YEAR– returns an integer corresponding to the year specified
SELECT DAY(GETDATE()) AS 'Day';
SELECT MONTH(GETDATE()) AS 'Month';
SELECT YEAR(GETDATE()) AS 'Year';