Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Format time

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
samprg
Asked:
samprg
  • 3
  • 2
1 Solution
 
knightEknightCommented:


select right( CONVERT(varchar, dateadd(HH,  DATEPART(hh,MyTime), convert(int,MyTime) ) ,100 ) ,7)
0
 
knightEknightCommented:
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
 
samprgAuthor Commented:
good,
I am sorry, I need to add minutes
0
 
knightEknightCommented:
ah, well that's actually easier!  :)

select right( CONVERT(varchar, MyTime ,100 ) ,7)
0
 
samprgAuthor Commented:
Awesome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now