0

I have table Proccesses that consist of Date Time Field.

Proccesses ( Id as int , RunDate as DateTime)

I need to run Distinct by RunDate as Time Without seconds

For Example

ID        RunDate 
1         2011-12-13 12:36:26.483
2         2011-12-12 12:37:22.421
3         2011-12-11 12:36:44.421

I need to receive in output

Output
12:36
12:37

I tried to use DatePart but did not manage

Please help

0

4 Answers 4

3

This should work:

SELECT DISTINCT DATENAME(hour, RunDate) + ':' + DATENAME(minute, RunDate) AS Output...
Sign up to request clarification or add additional context in comments.

1 Comment

The problem if I have in hour part 8 I need to convert to "08" . How can I do it ?
1

For SQL Server

select CAST(DATEPART(hour, RunDate) as varchar) + ':' + CAST(DATEPART(minute, RunDate) as varchar)

5 Comments

he needs a distinct selection.
Why CAST(DATEPART)? DATENAME returns a string.
The problem if I have in hour part 8 I need to convert to "08" . How can I do it ?
you can add each part to a "0" string, then take the rightmost 2 characters ie Right("0" + Cast(Datepart(hour, RunDate) as varchar),2)
@BrianDriscoll that's right; I always forget about DATENAME. Trap of familiarity I suppose.
0

Try

  • for hours: DATEPART(hh, RunDate)
  • for minutes: DATEPART(mi, RunDate)

1 Comment

The problem if I have in hour part 8 I need to convert to "08" . How can I do it ?
-1
select CONVERT(varchar,RunDate,103) + ' ' + CONVERT(varchar(5),RunDate,108)

(in Sql Server)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.