PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WD20] SQL - Add Days to Date
[WD20] SQL - Add Days to Date
Iniciado por guest, 23,mar. 2016 16:08 - 2 respuestas
Publicado el 23,marzo 2016 - 16:08
I have an SQL query with a subselect that uses case statements to return Date and Days. Is there a way to add the Days to the Date and still have a valid Date?

The following code is as far as I have gotten. The last line won't work all the time.
20161105 + 30 days = 20161135 instead of 20161205. If I get rid of WL.Val() it appends the two expressions as strings (20161105 + 30 = 2016110530).

SELECT * FROM( SELECT ID,CASE WHEN Date3 <> '' THEN Date3 WHEN Date2 <> '' THEN Date2 WHEN Date1 <> '' THEN Date1 ELSE '' END AS Date, CASE WHEN Date3 <> '' THEN Days3 WHEN Date2 <> '' THEN Days2 WHEN Date2 <> '' THEN Days1 ELSE '' END AS Days) FROM Schedule WHERE Date <> '' AND Days <> '') WHERE WL.Val(Date) + WL.Val(Days) > SUBSTRING(SysDate,0,8)
Publicado el 23,marzo 2016 - 16:27
Hey Curtis,

If you know the number of days, then why not turn your logic around a bit so the result is the difference (in days) between 2 dates like in this example?
http://doc.windev.com/en-US/…
Publicado el 23,marzo 2016 - 16:45
Good call.

WHERE WL.DateDifference(Date,SUBSTRING(SYSDATE,0,8)) > Days
Thanks!