PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WB19] SQL and Dates
[WB19] SQL and Dates
Iniciado por guest, 10,nov. 2015 12:07 - 4 respuestas
Publicado el 10,noviembre 2015 - 12:07
Hi

Anybody know how I can add x number of days to a date field through a query.

I want to get something like this

SELECT LastServiceDate, LastServiceDate + ServiceInterval from Service

The service interval can be between 30 or 360 and I want to get the machines due for a service in this month.

I have tried with CAST but you cannot cast a date to an integer and back so there must be some other trick.

Thanks in advance.



Ericus Steyn
Publicado el 10,noviembre 2015 - 12:20
Hi Ericus,

You don't need to add anything in SQL, just use:
"SELECT * FROM Service WHERE LastServiceDate BETWEEN '%1' AND '%2' ORDER BY LastServiceDate"
Do the date calculation on the parameters.

Regards,
Piet
Publicado el 10,noviembre 2015 - 13:14
Thanks Piet

Will give it a try.
Publicado el 10,noviembre 2015 - 13:44
Hi Ericus,
In this case the Piet solutions is the best one but if your db is in HFSQL you can use WLanguage functions in the SQL, check this info:

http://doc.windev.com/en-US/…
Publicado el 11,noviembre 2015 - 06:38
Hi Ericus,

do not use "between" when you the field is datetime . depend on the database server that you using, you may endup filter out some valid data

use the following method (for MSSQL)

(transdate >= @D1 and transdate < dateadd(d,1,@D2))