Macro to calculate value of diary

Version: 7.5.7.1 (X86_64) / LibreOffice Community
Build ID: 47eb0cf7efbacdee9b19ae25d6752381ede23126
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: pt-BR (pt_BR.UTF-8); UI: pt-BR
Calc: threaded

Evening, Im in need of a macro to calculate the value of a diary. I have a table that stores two dates, the entering date and the leaving date, I need the macro to calculate the difference between these two like, enter date 11/13/2023 and leave date 11/16/2023, equals 4 days (13,14,15,16), and then multiplies it by the value of the diary, example, 4*160, and finally display it in a text box on the form. Is there a way to do it? Thanks.

SELECT *, DateDiff('dd',"Date1","Date2")AS "Days" 
FROM "Table"

should I turn this into a query?

Yes, turn it into a query. Or use it directly in a form with source type SQL.

I think I’ll have to put it inside a macro, because the dates are variable

My query selects all rows and all columns from a table named “Table” plus the calculated column “Days” showing the differences between all values in columns named “Date1” and “Date2”.
You would not rewrite spreadsheet functions in Basic, just because you don’t know the formula language, would you?

I get it now, thanks

Actually, even after I changed the values so it matches my case, it is not creating the query.
Im using this SQL:

SELECT *, DateDiff('dd',"DataEntrada","DataSaida")AS "Days" FROM "DBCarro"

DataEntrada is the first date and DataSaida is the second date, theyre both inside the table DBCarro, but when I try to save it I get a syntax error.

Try "DBCarro".*, ... with the table name and a point in front of * which stands for “all columns”.

1 Like

It worked, thanks