Home > Enterprise >  How can i get a specific time of a date using SQL-Code
How can i get a specific time of a date using SQL-Code

Time:05-02

How can i get a specific time of a date using SQL-Code?

Today is 02.05.2022 16:45:00 using -> SELECT GETDATE()

What i need is 03.05.2022 8:00:00 -> ?

What would be the SQL-Code for it?

Tnx

EDIT:

I can get the tomorrows date using -> SELECT DATEADD(day, 1, GETDATE())

but i actually need the date of tomorrow at 8 a Clock.

CodePudding user response:

Today is 02.05.2022 16:45:00 using -> SELECT GETDATE() What i need is 03.05.2022 8:00:00 -> ?

Given your required date is "tomorrow" with no other narrative of requirements, the following is maybe what you are expecting:

select Convert(datetime,Convert(date,DateAdd(day,1,GetDate())))   Convert(datetime, '08:00')

CodePudding user response:

SELECT DATEADD(HOUR, 8, CAST(CAST(GETDATE() 1 AS DATE) AS DATETIME))

CodePudding user response:

Try

SELECT CAST('2022-05-03 8:00:00' AS DATETIME) AS NewDate

Regards,

CodePudding user response:

Assuming SQL Server, try this:

select convert(datetime,'03/05/2022 8:00:00')
  •  Tags:  
  • sql
  • Related