HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Get minute part from time data type

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
parttimetypegetfromdataminute

Problem

With the time data type (I'm using Microsoft SQL Server 2008), is there any way to take only the minute part out of it? I tried to pass the time to datepart and datediff function but both refused to work.

Example: I want to get 15 from 04:15

Solution

select datepart(minute, '04:15')


Utilize the DATEPART() function, with minute as the datepart param.

declare @current_time time

select @current_time = getdate()

select datepart(minute, @current_time) as current_minute


BOL Reference on DATEPART

Code Snippets

select datepart(minute, '04:15')
declare @current_time time

select @current_time = getdate()

select datepart(minute, @current_time) as current_minute

Context

StackExchange Database Administrators Q#16704, answer score: 12

Revisions (0)

No revisions yet.