简体   繁体   中英

How to change time(7) format from 24 to 12?

I have a variable as time(7) , but it gives me values like: '17:25' . I'd like for it to be in this format: '5:25 PM' . Is there a way to do this in SQL 2012 without doing something like this:

DECLARE @aux NVARCHAR(8)='16:45:00'
SELECT CONVERT(VARCHAR(15),CAST(@aux AS TIME),100)

Code gotten from here

No, you cannot do anything about the format SQL Server uses to store the Time datatype. You can only use tricks like the one you mentioned at query-time to deliver the output in a desired format. Or better yet, do the formatting in the front-end application.

您可以尝试将DATEPART(HH ...)与case语句或IF / ELSE一起使用,以更改中午之后的时间,最后使用CONCAT上午或下午

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM