How to add minutes(INT)
to the time part of datetime
?
For example :
If i have datetime variable like this :
@shift_start_time = 2015-11-01 08:00:00.000 @increase = 30
How to get the result :
2015-11-01 08:30:00.000
The DateTime. AddMinutes() method in C# is used to add the specified number of minutes to the value of this instance. It returns the new DateTime.
To add minutes to a datetime you can use DATE_ADD() function from MySQL. In PHP, you can use strtotime(). select date_add(yourColumnName,interval 30 minute) from yourTableName; To use the above syntax, let us create a table.
We can use DATEADD() function like below to add minutes to DateTime in Sql Server. DATEADD() functions first parameter value can be minute or mi or n all will return the same result.
DECLARE @dt DATETIME = '2021-12-31 00:00:00.000' SELECT DATETIMEFROMPARTS( DATEPART(YEAR, @dt), DATEPART(MONTH, @dt), DATEPART(DAY, @dt), 23, /* hour */ 59, /* minute */ 59, /* second */ 0 /* fractional seconds*/ );
Use DATEADD
:
SELECT DATEADD(mi, @increase, @shift_start_time);
db<>fiddle demo
Using dateadd:
DATEADD(minute,@increase,@shift_start_time)
the first argument can be chosen among: year quarter month dayofyear day week weekday hour minute second millisecond microsecond nanosecond
please check https://msdn.microsoft.com/it-it/library/ms186819%28v=sql.120%29.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With