[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

change time format in sql - easier to read

How can I change the format of the HourTimeFrom and HourTimeTo columns to this format?

9:00am
10:00am

temp
0
al4629740
Asked:
al4629740
  • 3
  • 2
  • 2
1 Solution
 
sammySeltzerCommented:
How about this:

SELECT ltrim(right(convert(varchar(25), HourTime, 100), 7))

Open in new window

0
 
al4629740Author Commented:
Does this take significantly more time to process?  rather than changing the datatype?
0
 
sammySeltzerCommented:
Not really. However, it is always a good idea to keep date and time as one field -DateTime.

You can still separate them programmatically but it is better to have one fieldname than two, Date and Time.
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
al4629740Author Commented:
Ok
Thank you
0
 
PortletPaulCommented:
from SQL 2012 onward you can use FORMAT()

select format(hourFromTime,'h:mm tt')

for a list of styles using convert (like the style 100 used before)
0
 
al4629740Author Commented:
Between your solution and Sams solution which one is better?
0
 
PortletPaulCommented:
there isn't much between them

I would use format() if it is available to you, as it is easier to understand and maintain IMHO
I do not think you will detect a measurable performance differential

- but "ltrim(right(convert" is 3 functions -v- format() which is one function
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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