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
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
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),':','');
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.