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 |
snufse
Constraint Violating Yak Guru
469 Posts |
Posted - 2008-09-24 : 08:58:29
|
I have a query that selects a "time" field. I need to display time as AM/PM time. Presently time shows as military. Thank you.myAdsSelectString = "select ticket_number, ticket_date, ticket_time from salestkt where shift_started >= " & "'" & myDateTimeValue & "'" & " order by ticket_id" |
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-09-24 : 09:10:35
|
This can be done in front end application and is advisable to be done there. |
|
|
snufse
Constraint Violating Yak Guru
469 Posts |
Posted - 2008-09-24 : 09:53:23
|
Since I am using GridView and BoundFileds in my application, I have not had any sucess doing it there. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-24 : 10:14:13
|
What is the datatype of ticket_time column?MadhivananFailing to plan is Planning to fail |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2008-09-24 : 10:26:24
|
Try thisselect CONVERT(varchar(20),getdate(),103) + ' '+ LTRIM(STUFF(right(CONVERT(varchar(30), getdate(), 9), 14), 9, 4, ' '))you can replace getdate() with the column where you are saving the time. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-24 : 10:56:59
|
[code]SELECT PARSENAME(RIGHT(REPLACE(CONVERT(VARCHAR(26), GETDATE(), 100), ' ', '.'), 7), 1), PARSENAME(RIGHT(REPLACE(CONVERT(VARCHAR(26), GETDATE(), 109), ' ', '.'), 14), 1)[/code] E 12°55'05.63"N 56°04'39.26" |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-09-24 : 11:01:20
|
quote: Originally posted by snufse Since I am using GridView and BoundFileds in my application, I have not had any sucess doing it there.
Bound fields are very easy to format if you return data with the proper type -- in this case, DateTime. You can do all kinds of formatting with the DateFormatString property:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspxIt's simple, it's easy, it's flexible, it's the way things are designed to be done.Never, ever do this in T-SQL when you have a perfectly fine front-end application that can handle it.*PLEASE* ignore the other advice given in this thread showing convoluted ways in T-SQL to convert things to VARCHARS.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
|
|
|
|
|