2

I want to Convert time to 0000 format. I'm using SQL Server 2017.

I've written the following query :

SELECT EventName, Convert(time, EventTime) as 'Log out' 
From AttendanceEvents

Which gives:

enter image description here

The Format I want my Time to be is :

1344
0032
1005
2013

and So on..

D-Shih
  • 44,943
  • 6
  • 31
  • 51
Dawood Zaidi
  • 278
  • 4
  • 16

1 Answers1

2

You can try to use CONVERT third parameter set 108 will get a hh:mi:ss string, then get front 5 characters and REPLACE :.

SELECT REPLACE(CONVERT(varchar(5), EventTime, 108), ':', '')

or use FORMAT function.

SELECT FORMAT(GETDATE(),'hhmm')

Query 1:

SELECT FORMAT(GETDATE(),'hhmm')

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

Results:

|      |
|------|
| 0718 |
D-Shih
  • 44,943
  • 6
  • 31
  • 51