1 (edited by borisavljevic 2021-08-25 22:45:16)

Topic: [SOLVED] cript to calculate days difference between two dates

Hello,

I searched forum and all I can find is solution with two DateTimePickers, What I need is script to select max date from table1 > field date, select min date from table1 > field date and calculate days difference > max date - min date and get result as integer. I know how to do that using calculated field but I need script because I want to show that result in Form1.Edit1 on OnShow.

Thanks in advance,

Vladimir

2 (edited by derek 2021-02-03 14:07:07)

Re: [SOLVED] cript to calculate days difference between two dates

Hi Vladimir,
As I understand it, you want to use a single date as a parameter and then
1.  find the minimum date in a table after that parameter date
2.  find the maximum date in a table after that parameter date
3.  calculate the difference between the maximum and the minimum dates.
If that's correct, then you could perhaps try to do it like this (please see the attached).
However, I'm sure there must be a simpler way (but I'm rubbish when it comes to working with dates!).
I have left all the fields visible so you can see what is being calculated but just make the ones you don't want to see invisible.
You may need to alter the calculation depending on whether you want the date you are using as a parameter to be included in the calculation or not.
I haven't put any error checking in place for invalid dates etc.
Hope this helps,
Derek.

Post's attachments

Attachment icon vladimir.zip 338 kb, 286 downloads since 2021-02-03 

Re: [SOLVED] cript to calculate days difference between two dates

Hi Derek, tnx for answer,

Thing is that I dont't want to use tablegrid, what I meant is to use data (datefield) from database table writing script.
Something like this:

days_diff = SQLExecute(('SELECT MAX(dalevery_date) FROM deliveries') - ('SELECT MIN(dalevery_date) FROM deliveries')) ;

and get result - number of days as integer because i need to do some other calculations with it later.

Anyway, thanks for your time.

Vladimir

4 (edited by derek 2021-02-03 17:19:10)

Re: [SOLVED] cript to calculate days difference between two dates

The tablegrid isn't been used in the calculation - it's there because it's difficult to test if you can't see what dates are actually in your table.
Anyway, I remembered an easier way to perform the calculation to show the difference between the min and max dates (in days) of the whole table,; try it like in the attached.
Derek.

Post's attachments

Attachment icon vladimir2.zip 336.8 kb, 335 downloads since 2021-02-03 

Re: [SOLVED] cript to calculate days difference between two dates

Thank you very much Derek, that's what I was looking for.