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 |
JeffS23
Posting Yak Master
212 Posts |
Posted - 2007-04-16 : 18:44:20
|
I am having a minor issue with the Minute section of this coding ... if the time is 8:00 AM, I am getting 8 for the hour and just one 0 on the minute. Maybe Im overlooking something obvious ... how can I get this to show 00 and not 0? StrtHour=convert(varchar(2),datepart(hour,Start)), StrtMin=convert(varchar(2),datepart(minute,Start)), StpHour=convert(varchar(2),datepart(hour,Stop)), StpMin=convert(varchar(2),datepart(minute,Stop)), |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-16 : 18:50:47
|
Don't format data in T-SQL, do it at your front-end. It is much easier and quicker to return the raw data and let your web page, report or application format the date and/or time any way you want. T-SQL is simply not designed to do this, it is designed to manipulate and return raw data, not to make things look nice.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
JeffS23
Posting Yak Master
212 Posts |
Posted - 2007-04-16 : 18:57:15
|
So is this impossible to do ... I can re-direct my attention over to Crystal Report formatting if so. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-04-16 : 19:04:30
|
It is not impossible to do. It isn't recommended though.What Jeff is saying is to return your Start and Stop columns as is with no formatting to your report, then have Crystal Reports do the formatting that you need.Tara Kizerhttp://weblogs.sqlteam.com/tarad/ |
 |
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2007-04-18 : 01:51:01
|
[code] SELECT StrtHour = CONVERT(CHAR(2),GETDATE(),108), StrtMin = RIGHT(CONVERT(CHAR(5),GETDATE(),108),2)[/code]--Jeff Moden |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-04-18 : 01:57:40
|
quote: Originally posted by Jeff Moden
SELECT StrtHour = CONVERT(CHAR(2),GETDATE(),108), StrtMin = RIGHT(CONVERT(CHAR(5),GETDATE(),108),2)
Grrr... Tara Kizerhttp://weblogs.sqlteam.com/tarad/ |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-18 : 08:13:37
|
Some people insist on giving bad advice here, unfortunately. I guess that's what you get with forums .... a lot of times, you get great advice, but you also get people who don't follow (or understand) best practices as well.The sad thing is that this individual has participated in quite a few discussions with me about where to format and present data, and each time at the end he was forced to agree, but then he keeps completely disregarding what he learned and recommending to people to do things the harder, more complicated way.see: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76862It's frustrating. What sucks is, if someone asks for an answer and you explain to them a better, easier and more correct approach and someone else just shows them bad code that "works", the person will always ignore what you took the time to wrote and what you are trying to teach them regarding best practices and they will just cut and paste the code they see and be happy and move on, making even a bigger mess of what they are working on and not learning a damn thing. Which is really not the point of where we are here, I always thought. On an unrelated note, lots of "Jeff's" in this thread .... - Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
|
|
|
|