-2

I need how to get the last one hour in format 'hhmmss' in sql server for example if the time now is 10:48:22 i need the expected result be 9:48:22

the time now -1

Lamis Alaa
  • 59
  • 1
  • 6

2 Answers2

0

Assuming that you mean you want the time for the current hour (so for me right now, its 09:39 so you want '090000') then this would get what you're after:

SELECT REPLACE(CONVERT(varchar(8),DATEADD(HOUR, DATEDIFF(HOUR,'20000101',GETDATE()),'20000101'),14),':','');
Thom A
  • 88,727
  • 11
  • 45
  • 75
0

You appear to want:

select convert(varchar(8), cast(dateadd(hour, -1, getdate()) as time))

However, I you can probably also leave the value as a time rather than converting to a string.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786