Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
declare @Table1 TABLE 
( TimeSchedule time , 
  Duration time , 
  EnteredOn datetimeoffset )

Insert @Table1 values ( CAST(0x00907E0000000000 AS Time), CAST(0x0008070000000000 AS Time),'2015-11-24')

Insert @Table1 values ( CAST(0x00A08C0000000000 AS Time), CAST(0x0008070000000000 AS Time),'2015-11-24')

SELECT CONCAT(CONVERT(DATE,EnteredOn), ' ' , TimeSchedule,' to ', (CONVERT(VARCHAR(8),CONVERT(DATETIME,TimeSchedule)+ CONVERT(DATETIME,Duration),108)) ) AS Daytime FROM @Table1

OUTPUT:
2015-11-24 09:00:00 to 09:30:00
2015-11-24 10:00:00 to 10:30:00

I want my output as 2015-11-24 09:00:00 to 10:30:00. Plz help me to find ts.
Posted
Updated 23-Nov-15 20:44pm
v2
Comments
Tomas Takac 24-Nov-15 2:47am    
You need to insert duration of 1h 30m instead of just 30m. That will solve your problem.

1 solution

Hi,
Please try below query



SQL
declare @Table1 TABLE 
( TimeSchedule time , 
  Duration time , 
  EnteredOn datetimeoffset )
 
Insert @Table1 values ( CAST(0x00907E0000000000 AS Time), CAST(0x0008070000000000 AS Time),'2015-11-24')
 
Insert @Table1 values ( CAST(0x00A08C0000000000 AS Time), CAST(0x0008070000000000 AS Time),'2015-11-24')
 
SELECT CONCAT(CONVERT(DATE,EnteredOn), ' ' , TimeSchedule,' to ', (CONVERT(VARCHAR(8),dateadd(hh,CAST(CONVERT(DATETIME,TimeSchedule ) AS bigint),'1/1/1970 10:00:00')  + CONVERT(DATETIME,Duration),108)) ) AS Daytime FROM @Table1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900