Skip to content

Instantly share code, notes, and snippets.

@fernandezja
Created November 14, 2023 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandezja/fa08d06688a2b9888b9ca4299444c0cc to your computer and use it in GitHub Desktop.
Save fernandezja/fa08d06688a2b9888b9ca4299444c0cc to your computer and use it in GitHub Desktop.
Add time to date SQL Server
--Add time to date SQL Server
--------------------------------------------------------------
DECLARE @Hour TIME = '20:00',
@Today VARCHAR(10) = CONVERT(VARCHAR(10), GETDATE(), 121)
DECLARE @TodayWithHourString VARCHAR(100) = CONCAT(@Today, ' ', @Hour)
DECLARE @TodayWithHour DATETIME2(0) = CONVERT(DATETIME2(0), @TodayWithHourString)
SELECT
Hour = @Hour,
Today = @Today,
TodayWithHourString = @TodayWithHourString,
TodayWithHour = @TodayWithHour
@fernandezja
Copy link
Author

Example
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment