Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql server 2000 convert datetime to get hhmm

I'm using

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

to convert getdate() to yyyymmdd format (ISO format), which works great. Now I need to do something similiar 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.

like image 360
MAW74656 Avatar asked Nov 14 '11 18:11

MAW74656


People also ask

How do I get HH mm in SQL Server?

By using format code as 108 we can get datetime in “HH:mm: ss” format. By using format code as 109 we can get datetime in “MMM DD YYYY hh:mm:ss:fff(AM/PM)” format. By using format code as 110 we can get datetime in “MM- DD-YY” format. By using format code as 111 we can get datetime in “YYYY/MM/DD” format.

How do I get HH from datetime in SQL?

How do I get HH MM SS from date in SQL? SELECT convert(varchar, getdate(), 108) outputs as hh:mm:ss .

How can get minutes and seconds from datetime in SQL?

The HOUR() , MINUTE() , and SECOND() functions extract the hours, minutes, and seconds from a date or datetime value respectively. And if you're working with a higher precision, you can use the MICROSECOND() function to return the microseconds part.


2 Answers

SELECT REPLACE(CONVERT(varchar(5), GETDATE(), 108), ':', '')
like image 173
stuartd Avatar answered Sep 21 '22 11:09

stuartd


SELECT REPLACE(CONVERT(CHAR(5),GETDATE(),108), ':', '')

If you don't need colon, just remove it...

like image 21
Alexander Galkin Avatar answered Sep 20 '22 11:09

Alexander Galkin