Solved

Format time

Posted on 2011-09-13
5
247 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 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