Sql server 2000 convert datetime to get hhmm

I use

convert(varchar(20), getdate(), 112) 

convert getdate () to yyyymmdd format (ISO format), which works great. Now I need to do something similar to get the time in hhmm format. How can i achieve this?

Example: 12:10 pm should look like 1210, 3:43 pm should look like 1543.

+6
source share
3 answers
 SELECT REPLACE(CONVERT(varchar(5), GETDATE(), 108), ':', '') 
+17
source
 SELECT REPLACE(CONVERT(CHAR(5),GETDATE(),108), ':', '') 

If you don't need a colon, just delete it ...

+3
source

DO NOT do just the date in hours, get the date in minutes and connect, since 19:05 will end before 195. If you go this route, you will need to do something like this in order to deal with the minutes

right ('0' + varchar (datepart (mi, getdate ())), 2)

at this moment it becomes quite ineffective.

0
source

Source: https://habr.com/ru/post/901455/


All Articles