I’m not sure that’s what you’re looking for, but you can work that way:
Schema
test:
CREATE TABLE teste
([HORA] VARCHAR(20))
;
INSERT INTO teste
([HORA])
VALUES
('24:00'),
('10:00'),
('5:20')
;
SELECT
CONCAT(CONVERT(CHAR(10), getdate(),126),' ',HORA,':00') AS HORA_FECHAMENTO,
CONVERT(VARCHAR(20), DATEADD(hour, +0, getdate()), 120) AS HORA_ATUAL
FROM teste
Explaining the line: CONCAT(CONVERT(CHAR(10), getdate(),126),' ',HORA,':00')
I only take the date in the format yyyy-mm-dd
and concateno with the time that is in the comic, along with the seconds, which also were not defined.
Note that there are logical errors in your comic book, the ideal would be to work the two dates with the same format, yyyy-mm-dd hh:mm:ss
, the way you are "forcing" the closing day to be today.
See working on Sqlfiddle
The function concat
is not implemented in sql-server 2008
, how output the solution can be:
SELECT
CONVERT(CHAR(10), getdate(),126)+' '+HORA+':00') AS HORA_FECHAMENTO,
CONVERT(VARCHAR(20), DATEADD(hour, +0, getdate()), 120) AS HORA_ATUAL
FROM teste
There is a problem in the current logic, closing time may be related to any day
– MarceloBoni
@itasouza: There is no 24:00. From 23:59 it goes to 0:00. In the example you posted, it would be 2017-01-28 23:59:59 or so 2017-01-29 0:00:00. Which prefer?
– José Diz
Suggestion, do not change the question like this, add information at the end of it, not to misread the initial question.
– MarceloBoni