Home > Enterprise >  How to subtract an interval from a datetime?
How to subtract an interval from a datetime?

Time:01-02

How to calculate start_time given finish_time and différent_time?

Ex:(2021-10-12 23:50:00 - 30s = 2021-10-12 23:20:00

différent_time is the quantity of seconds.

CodePudding user response:

You can just subtract the different_time from the finish_time. Here's an example using variables (hence, the @ sign) instead of field values, but it should get you on your way.

declare @finish_time as datetime = '12:00:00'
declare @start_time as datetime
declare @different_time as datetime = '0:00:30'

set @start_time = @finish_time - @different_time

select @start_time

This will return a time that is 30 seconds earlier than your finish time. In this case: 11:59:30 AM.

In a query, it would look something like this:

select [finish_time] - [different_time] as [start_time]

CodePudding user response:

Because in my application I have only the column finish_time and the column time period of the video. So in this case I want to calculate the start time of the videos. To remind the time period of the video, it is expressed by seconds. Here are some examples of time periods: 2345s, 209s, 30s........ Can help me please.

Sorry about my English is not good

  • Related