Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Format time

Posted on 2011-09-13
5
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 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