Author |
Topic |
suchiate
Starting Member
33 Posts |
Posted - 2006-09-24 : 12:13:46
|
Hey guys.. I am having difficulties in returning the time in the format that I want...i want to return the hours and minutes in 2 values such that:3AM = 03:00but it will only return 3:0 if i use the datepart(hh...) and datepart(mi...)... how can we always make them appear as two values? help me out pls.. thanks! |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2006-09-24 : 12:57:09
|
Post your code? We'll correct it for you. |
 |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2006-09-24 : 12:59:04
|
I think you are asking for a method which will include leading zeros...RIGHT('0' + DATEPART(...), 2)Sam |
 |
|
suchiate
Starting Member
33 Posts |
Posted - 2006-09-24 : 13:04:30
|
Select convert(varchar(2),datepart(hh,getdate())) + convert(varchar(2),datepart(mi,getdate())) as time |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-09-24 : 13:25:13
|
As a rule of thumb, you should never format your data in T-SQL. Return the raw data to your client/reporting tool, and let the presentation layer format it any way that it wants. T-SQL is not designed for formatting or outputing data. You can do it with some work, but the result is that everything must be converted to varchar's and now you are no longer returning data in the proper type.- Jeff |
 |
|
suchiate
Starting Member
33 Posts |
Posted - 2006-09-24 : 13:28:34
|
yes i converted into varchar but i am still not getting the leading zeros...i have tried SamC's method but the leading zero still dont work.. |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-09-24 : 14:06:48
|
[code]select [HH:MM] = convert(varchar(5),getdate(),108)[/code]Results:[code]HH:MM ----- 14:04(1 row(s) affected)[/code]CODO ERGO SUM |
 |
|
suchiate
Starting Member
33 Posts |
Posted - 2006-09-24 : 14:07:54
|
guys thanks for the help.. i managed to figure out already..thanks alotbelow is the code...RIGHT('0' + (Convert(varchar(2),DATEPART(...)), 2) |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-09-24 : 20:45:04
|
Where do you want to show data?If you use front end application, as suggested, do the formation thereMadhivananFailing to plan is Planning to fail |
 |
|
|