0
I get a date, and I need to know if it’s valid, if it’s not, I need to shorten her day until it’s valid.
set @data = (select convert(date,CONCAT(@dia,'-',month(@vencimento1),'-',year(@vencimento1))))
set @vencimento = (select DATEADD(month, 1, @data))
I tried something like:
if (select isdate(DATEADD(month, 1, @data))) = 1
set @vencimento = (select DATEADD(month, 1, @data))
else
set @vencimento = (select dateadd(day, -1, @data), DATEADD(month, 1, @data))
But it doesn’t work either. What would be the best way to check ?
EDIT
I arrived at this code with the junction of the answers:
while(isdate((CONCAT(@dia,'-',month(@vencimento1),'-',year(@vencimento1)))) = 0 )
set @dia = @dia - 1;
set @data = (select convert(date,CONCAT(@dia,'-',month(@vencimento1),'-',year(@vencimento1))))
print @data
set @vencimento = (select DATEADD(month, 1, @data))
But what happens, it does not generate the correct day, it was to generate for example on 31/12, it generates pro day 30/12, and on January 31/01, and in February it takes day 29.
What DATE would that be? Why has 2 due dates and date? can only be useful days?
– wallafe sousa