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 |
|
krithika
Starting Member
1 Post |
Posted - 2011-06-24 : 02:22:06
|
| I am new Sql server 2005.Could you ppl give me idea for querry to have format of HH:MM:AM/PM (say 11:57:AM)I tried this querry,but i need a colon to be inserted after minutedeclare @date datetimeset @date = '20:01'SELECT CONVERT(VARCHAR(5), @date, 108) + ' ' + SUBSTRING(CONVERT(VARCHAR(19), @date, 100),18,2)Advance Thanks,Krithi |
|
|
chris_cs
Posting Yak Master
223 Posts |
Posted - 2011-06-24 : 03:42:44
|
| Not sure it's the best way to do it but this works:declare @date datetimeset @date = '20:01'SELECT REPLACE(CONVERT(VARCHAR(5), @date, 108) + ' ' +SUBSTRING(CONVERT(VARCHAR(19), @date, 100),18,2), ' ', ':')Junior DBA learning the ropes |
 |
|
|
Ranjit.ileni
Posting Yak Master
183 Posts |
Posted - 2011-06-24 : 07:57:37
|
| SELECT SUBSTRING(CONVERT(VARCHAR(20), GETDATE(), 9), 13, 5) + ':' + SUBSTRING(CONVERT(VARCHAR(30), GETDATE(), 9), 25, 2) AS TIME--Ranjit |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-24 : 09:02:16
|
| select stuff(right('0'+ltrim(right(CONVERT(varchar(20),getdate(),100),7)),7),6,0,':')==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-06-29 : 04:10:00
|
| Always use datetime datatype to store data and do the formation at the front end applicationMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|