开发者

How to get Exact Time format using select query

I'm using below query to get the time a开发者_Python百科s AM/PM format eg:- if time is 2011-10-10 13:10:10 in database it will return as 1:10 PM

I just want to fetch like 01:10 PM

I used below query to fetch the above result

  SELECT SUBSTRING(CONVERT (varchar,FromDateTime,100),13,7)+' - '+SUBSTRING(CONVERT                             
  (varchar,ToDateTime,100),13,7) as EventTime FROM tblEvent

How to get the time time like 01:10 AM


You could convert the datetime value using the default format, then extract the time portion and slightly modify it to guarantee the leading zero's presence when it's needed:

SELECT RIGHT('0' + LTRIM(RIGHT(CONVERT(varchar, GETDATE()), 7)), 7)


you can directly use convert with 108 as parameter

see here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜