How to timestamp a new record

Creating and using forms
Post Reply
hypGnosis
Posts: 16
Joined: Fri Apr 26, 2013 10:40 pm

How to timestamp a new record

Post by hypGnosis »

Using Base Forms, is it possible to timestamp (auto populate a field like "Record Created Date & Time")
OpenOffice 4.1.7 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to timestamp a new record

Post by Villeroy »

This is a feature of the underlying database.
Using HSQL:
menu:Tools>SQL:

Code: Select all

ALTER TABLE "TBL" ADD COLUMN "TS" TIMESTAMP DEFAULT CURRENT_TIMESTAMP
menu:View>Refresh Tables

Now every new record gets a timestamp in column TS unless you explicitly enter some date-time value.
On the form you either leave out the TS field or you add a label to it like "Timestamp (Blank=Now)".
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
hypGnosis
Posts: 16
Joined: Fri Apr 26, 2013 10:40 pm

Re: How to timestamp a new record

Post by hypGnosis »

Thank you for your reply, Villeroy. I've looked & looked all over (even in a LibreOffice forum), but to no avail. I am looking for a routine that would update the current record with a record creation timestamp; and if the record had previously been created, then the routine would opt for updating the Last Edited (recEdit) timestamp and not change the recCreate field. I was also looking for a routine that would find the time difference in two of the form's fields (Time Start & Time Stop) and display the difference in a textbox on the form and not save a calculation in the table ... only display it on the form every time a different record is displayed. No luck there either.

Now, I did not try your suggestion because I already have a recCreate field/column define in the table; and, I think that every time I executed your suggested SQL, I would have another, and then, another, and so on, every time I added a new record. The file might end up with a lot of "TS" fields.
OpenOffice 4.1.7 on Windows 10
Post Reply