• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • 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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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