How can I get the total minute for sql datetime?
Let's say:
select getdate() from table
In this way, I will get everything, but I only want to get total minute. For eg,
if the time is 07:10:35
, I want 430
.
How to achieve that?
The value from the field is 01-01-2001 07:10:40
The result I want is 430
((7*60)+10) only.
In order to convert a DateTime to a string, we can use CONVERT() and CAST() function. These functions are used to converts a value(of any datatype) into a specified datatype.
You can convert a DATETIME to a DATE using the CONVERT function. The syntax for this is CONVERT (datetime, format). This shows the date only and no time.
(DATEPART(HOUR,GETDATE()) * 60) + DATEPART(MINUTE,GETDATE())
Here's a sample:
DECLARE @dt datetime
SET @dt = '01-01-2001 07:10:20'
SELECT DATEDIFF(MINUTE, DATEADD(DAY, DATEDIFF(DAY, 0, @dt), 0), @dt)
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