Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

MSSQL – Datetime In Local Timezone

Posted on February 2, 2017March 26, 2021 By David Kittell

This function will get the local time based on the time zone difference from UTC

IF OBJECT_ID(N'[GetLocalDate]') IS NOT NULL
	DROP FUNCTION [GetLocalDate]
GO

CREATE FUNCTION [dbo].[GetLocalDate] (@TimezoneDiffInHour FLOAT = - 5)
RETURNS DATETIME
AS
BEGIN
	RETURN DATEADD(Hh, @TimezoneDiffInHour, GETUTCDATE())
END;
SELECT dbo.GetLocalDate(DEFAULT);
-- or
SELECT dbo.GetLocalDate(-5);
SELECT dbo.GetLocalDate(+1);
Originally Posted on February 2, 2017
Last Updated on March 26, 2021
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Azure Code MSSQL SQL

Post navigation

Previous post
Next post

Related Posts

Ektron List All PageBuilder Pages

Posted on January 5, 2015October 26, 2015

SET NOCOUNT ON DECLARE @Domain VARCHAR(50) SET @Domain = ‘/’ SELECT c.[content_id], c.[content_title], c.[content_html], CASE WHEN c.[content_status] = ‘A’ THEN ‘Approved’ WHEN c.[content_status] = ‘O’ THEN ‘Checked Out’ WHEN c.[content_status] = ‘I’ THEN ‘Checked In’ WHEN c.[content_status] = ‘S’ THEN ‘Submitted for Approval’ WHEN c.[content_status] = ‘M’ THEN ‘Marked for…

Read More

PowerShell – Windows DNS Server Basics

Posted on May 11, 2018

# Windows Version – Helps to know what version as some things change from one version to another. (Get-WmiObject -class Win32_OperatingSystem).Caption $ZN = "kittell.net" # List DNS Forwarders – Where to go if DNS record not in this DNS server Get-DnsServerForwarder # Remove DNS Server Forwards #Remove-DnsServerForwarder -IPAddress 8.8.8.8 -PassThru…

Read More

MSSQL Format U.S. Phone Number

Posted on October 13, 2014October 26, 2015

SELECT CASE LEN(phone) WHEN 11 THEN LEFT(phone, 1) + STUFF(STUFF(STUFF(phone, 1, 1, ‘ (‘), 6, 0, ‘) ‘), 11, 0, ‘-‘) WHEN 10 THEN STUFF(STUFF(STUFF(phone, 1, 0, ‘ (‘), 6, 0, ‘) ‘), 11, 0, ‘-‘) WHEN 7 THEN STUFF(phone, 4, 0, ‘-‘) ELSE ‘Invalid phone’ END AS ‘Formatted Phone’…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes