Saturday, July 21, 2012

SQL SERVER – Hints On Some function’s on Data & Time


The following DateTime Function are mentioning below-
1) GETDATE()

2) SYSDATETIME()

3) SYSDATETIMEOFFSET()

4) TODATETIMEOFFSET()

5) SWITCHOFFSET()

Examples:

-- Get date fucntion
SELECT GETDATE() GetDate_function;

-- get the sysdatetime function
Select SYSDATETIME() SysDateTime_function;

-- get SYSDATETIMEOFFSET function
SELECT SYSDATETIMEOFFSET() GetCurrentOffSet;

-- get TODATETIMEOFFSET fuction with SYSDATETIMEOFFSET function
SELECT TODATETIMEOFFSET(SYSDATETIMEOFFSET(), '-02:00') 'GetCurrentOffSet-2';
SELECT TODATETIMEOFFSET(SYSDATETIMEOFFSET(), '+00:00') 'GetCurrentOffSet+0';
SELECT TODATETIMEOFFSET(SYSDATETIMEOFFSET(), '+02:00') 'GetCurrentOffSet+2';

--get TODATETIMEOFFSET fuction with SWITCHOFFSET function
SELECT SYSDATETIMEOFFSET() GetCurrentOffSet;
SELECT SWITCHOFFSET(SYSDATETIMEOFFSET(), '-02:00') 'GetCurrentOffSet-2';
SELECT SWITCHOFFSET(SYSDATETIMEOFFSET(), '+00:00') 'GetCurrentOffSet+0';
SELECT SWITCHOFFSET(SYSDATETIMEOFFSET(), '+02:00') 'GetCurrentOffSet+2';

Result:




Like and Share to SQL Integrity Blog

No comments:

Post a Comment

Thank You !!!!