Hi Crew,
Just one question, you guys will probably know immediately.
I'd like to be able to input a date in one field and have a second field show that date, plus a set amount (1) of days.
eg: I input 25/06/2012 and the second field automatically shows 26/06/2012
Is there an easy way to achieve this?
Cheers,
Dunbar.
Adding a day to a given date
Adding a day to a given date
open office 3.1.1/windows XP
Re: Adding a day to a given date
The problem is that there are many ways how to do this. But not all are appropriate for your case.
You can do this in the database backend with a trigger on your table. This depends on your backend (shown in the status line of the Base window: Embedded Database, Mysql, PostgreSQl,...) And it is done invisible for the user when the data is written from the frontend form into the database record.
If the date in the second field is rather a (default) suggestion and the user should be able to modify/overule it then you need a different and more complicated method because you will have to use macros that modify the other field's data when the field with the first date is typed or modified.
So please specify the database backend that you are using and tell us a more details about the workflow of your form.
You can do this in the database backend with a trigger on your table. This depends on your backend (shown in the status line of the Base window: Embedded Database, Mysql, PostgreSQl,...) And it is done invisible for the user when the data is written from the frontend form into the database record.
If the date in the second field is rather a (default) suggestion and the user should be able to modify/overule it then you need a different and more complicated method because you will have to use macros that modify the other field's data when the field with the first date is typed or modified.
So please specify the database backend that you are using and tell us a more details about the workflow of your form.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: Adding a day to a given date
Thanks for the reply Rudulfo.
Status line says "Embedded Database" and then "HSQL Database Engine".
The second field does not need to be editable by the user, but it does have to be relative to the first field.
ie: if the first field is modified the second field has to change likewise.
Let me now if you need any more info.
Thanks for your help.
Dunbar
Status line says "Embedded Database" and then "HSQL Database Engine".
The second field does not need to be editable by the user, but it does have to be relative to the first field.
ie: if the first field is modified the second field has to change likewise.
Let me now if you need any more info.
Thanks for your help.
Dunbar
open office 3.1.1/windows XP
Re: Adding a day to a given date
Okay, that's one step further. The problem with triggers on the tables is that they operate hidden from the user. If the second date field is visible but readonly for the user, a reload of the data record would be required to show the automatically added date. The second date is only generated when the user changes the record.
I am not really familiar with the HSQL Database Engine, but I think that the one that is integrated in Base doesn't support triggers. Maybe anybody else here with some clearer statement? DACM? R4zoli?
So the only solution that I see is to use a macro that is bound to the "leave field" event. If you have never worked with macros or programming languages before you have to choices: Either find someone that can do it for you or set aside some days for learning the scripting interface of OpenOffice/Base (UNO API). Might be some fun after 3 or 4 weeks, but the first days will surely be paved with frustration.
I am not really familiar with the HSQL Database Engine, but I think that the one that is integrated in Base doesn't support triggers. Maybe anybody else here with some clearer statement? DACM? R4zoli?
So the only solution that I see is to use a macro that is bound to the "leave field" event. If you have never worked with macros or programming languages before you have to choices: Either find someone that can do it for you or set aside some days for learning the scripting interface of OpenOffice/Base (UNO API). Might be some fun after 3 or 4 weeks, but the first days will surely be paved with frustration.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: Adding a day to a given date
If the second field is always 1 day after the first field, meaning if the first field changes its value because the user or the admin of your application has modified it the second field is changing synchronously, then a view based on a query could do what you want to see. You don't need to have an extra column field2 in your table. With the clear rule "field2 is always field1 + 1day" the database can calculate (or auto-generate) the field 2 every time the data in the table is retrieved.
See this other thread about date functions in HSQLDB. Unfortunately HSQLDB makes it unnecessarily complicated compared to other databases like MySQL, PostgreSQL or Oracle.
Your Query:
See this other thread about date functions in HSQLDB. Unfortunately HSQLDB makes it unnecessarily complicated compared to other databases like MySQL, PostgreSQL or Oracle.
Your Query:
Code: Select all
select field1, dateadd(field2, INTERVAL 1 DAY) As field2 from ...
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: Adding a day to a given date
Hello
I agree with rudolfo macros are difficult. If possible try to redesign your form.
Other wise study this
http://www.oooforum.org/forum/viewtopic ... ateadd+sub
Romke
I agree with rudolfo macros are difficult. If possible try to redesign your form.
Other wise study this
http://www.oooforum.org/forum/viewtopic ... ateadd+sub
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Adding a day to a given date
Base does not provide GUI support for HSQLDB Triggers, but the function does exist in the built-in HSQLDB jar file and I presume it could be accessed through Tools>SQL... or a Macro.
HSQLDB 1.8.x supports external routines ("Java classes" stored as external files) accessed through the Trigger interface:
But even before going the coded route, take a look at this link which contains a few DATEADD workarounds using standard Queries/Views for the built-in HSQLDB 1.8.0.10:
HSQLDB 1.8.x supports external routines ("Java classes" stored as external files) accessed through the Trigger interface:
- http://hsqldb.org/doc/src/org/hsqldb/Trigger.html
http://hsqldb.org/doc/guide/ch09.html#c ... er-section
But even before going the coded route, take a look at this link which contains a few DATEADD workarounds using standard Queries/Views for the built-in HSQLDB 1.8.0.10:
AOO 4.1.x; LO 4.2.x; Windows 7/8 64-bit
Warning: Avoid embedded databases --> Solution: Adopt a portable 'split database' folder
Soli Deo gloria
Warning: Avoid embedded databases --> Solution: Adopt a portable 'split database' folder
Soli Deo gloria