Solved

Format time

Posted on 2011-09-13
5
241 Views
Last Modified: 2012-05-12
Him

I try to change the format for (DATEPART(hh, MyTime) * 100) if >1200 to 1:00 PM
So I need add AM/PM
Thanks
0
Comment
Question by:samprg
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 36531669


select right( CONVERT(varchar, dateadd(HH,  DATEPART(hh,MyTime), convert(int,MyTime) ) ,100 ) ,7)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36531719
The above assumes that MyTime is a datetime column, if it is a TIME column, then do this:

select right( CONVERT(varchar, dateadd(HH,  DATEPART(hh,MyTime), 0 ) ,100 ) ,7)
0
 

Author Comment

by:samprg
ID: 36531722
good,
I am sorry, I need to add minutes
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
ID: 36531814
ah, well that's actually easier!  :)

select right( CONVERT(varchar, MyTime ,100 ) ,7)
0
 

Author Closing Comment

by:samprg
ID: 36531850
Awesome
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now