Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
kaus
Posting Yak Master
179 Posts |
Posted - 2002-04-04 : 12:28:27
|
I'm using this statement to get hour:minute from date:SELECT (cast(datepart(hh,event_date)as varchar) + ':' + cast(datepart(mi, event_date)as varchar ))FROM eventsthe problem is that 9:00 always returns as 9:0 .. 8:00 returns 8:0 etc ..Is there someother way I could do this -- I've tried the 'n' abreviation and also used minute in the date part functionthanksPete |
|
jbkayne
Posting Yak Master
100 Posts |
Posted - 2002-04-04 : 12:42:25
|
Try:select left(convert(varchar, event_date, 108),5)FROM events |
|
|
efelito
Constraint Violating Yak Guru
478 Posts |
Posted - 2002-04-04 : 12:44:35
|
This should do it.SELECT (cast(datepart(hh,event_date)as varchar) + ':' + right('0' + cast(datepart(mi, event_date)as varchar ), 2)) FROM eventsJeff BanschbachConsultant, MCDBA |
|
|
kaus
Posting Yak Master
179 Posts |
Posted - 2002-04-04 : 12:47:01
|
thanks -- that worked great !!Pete |
|
|
Jay99
468 Posts |
Posted - 2002-04-04 : 13:00:21
|
Another approach would be...select replicate('0', 2-len(cast(datepart(hh,event_date) as varchar) + cast(datepart(hh,event_date) as varchar) <O>In this case efelito's solution is a bit easier on the eyes, but the replicate is nice for certain things ...Jay<O> |
|
|
kaus
Posting Yak Master
179 Posts |
Posted - 2002-04-04 : 19:11:24
|
quote: In this case efelito's solution is a bit easier on the eyes, but the replicate is nice for certain things ...
when would you want to use the replicate ??Pete |
|
|
|
|
|
|
|