How to add minutes to the time part of datetime
Use DATEADD
:
SELECT DATEADD(mi, @increase, @shift_start_time);
db<>fiddle demo
How to add hours, minutes and seconds to a datetime column in SQL?
I would use dateadd()
, but I would phrase it as:
select dateadd(second, 24 * 60 * 60 - 1, UpdatedTime)
Or just add a time value:
select UpdatedTime + '23:59:59'
Add hours/minutes to datetime
Not exactly pretty, but it works...
DECLARE @eventDateTime VARCHAR(50), @offset varchar(10)
SET @eventDateTime = '2020-09-30 5:00AM'
SET @offset = '-5:30'
SELECT CASE WHEN @offset LIKE '-%' THEN CONVERT(DATETIME,@eventDateTime) - REPLACE(@offset,'-','')
ELSE CONVERT(DATETIME,@eventDateTime) + REPLACE(@offset,'+','')
END
Add minutes to date during time changing
The big error you face is that the time does not go back on hour on 24. October but on 25.
You can try following code:
var date = new DateTime(2015, 10, 25, 1, 20, 00).ToUniversalTime();
Console.WriteLine($"UTC: {date}\tDST: {date.ToLocalTime().IsDaylightSavingTime()}\t{date.ToLocalTime()}");
date = date.AddMinutes(50);
Console.WriteLine($"UTC: {date}\tDST: {date.ToLocalTime().IsDaylightSavingTime()}\t{date.ToLocalTime()}");
date = date.AddMinutes(50);
Console.WriteLine($"UTC: {date}\tDST: {date.ToLocalTime().IsDaylightSavingTime()}\t{date.ToLocalTime()}");
date = date.AddMinutes(50);
Console.WriteLine($"UTC: {date}\tDST: {date.ToLocalTime().IsDaylightSavingTime()}\t{date.ToLocalTime()}");
and you will get for UTC+1 (CEST UTC+2) following output:
UTC: 24.10.2015 23:20:00 DST: True 25.10.2015 01:20:00
UTC: 25.10.2015 00:10:00 DST: True 25.10.2015 02:10:00
UTC: 25.10.2015 02:00:00 DST: False 25.10.2015 02:00:00
UTC: 25.10.2015 01:50:00 DST: False 25.10.2015 02:50:00
How to add/subtract time (hours, minutes, etc.) from a Pandas DataFrame.Index whos objects are of type datetime.time?
Liam's link looks great, but also check out pandas.Timedelta
- looks like it plays nicely with NumPy's and Python's time deltas.
https://pandas.pydata.org/pandas-docs/stable/timedeltas.html
pd.date_range('2014-01-01', periods=10) + pd.Timedelta(days=1)
Related Topics
Oracle 11G: Unpivot Multiple Columns and Include Column Name
Insert Large Amount of Data Efficiently with Sql
How to Search for Names with Apostrophe in SQL Server
How to Remove All Newline from a Variable in SQL Server
How to Group by and Concatenate Fields in Redshift
Ordering Distinct Column Values by (First Value Of) Other Column in Aggregate Function
Slow Performance for Deeply Nested Subquery Factoring (Cte)
How Do The SQL "Is" and "=" Operators Differ
Sql Server Login Disable Windows Authentication
How to Concat Multiple Rows into One Column in SQL Server
Index Spanning Multiple Tables in Postgresql
Whats The Best Sqlite Data Type for a Long String
Writing SQL Query for Getting Maximum Occurrence of a Value in a Column
Find The Sids of The Suppliers Who Supply Every Part