[Solved] Create field that automatic stamps Current Date?

Creating tables and queries
Post Reply
DreamerArgentino
Posts: 17
Joined: Sun May 20, 2018 12:02 am

[Solved] Create field that automatic stamps Current Date?

Post by DreamerArgentino »

Hello everybody!!

Can I create a field that automatically stamps the current date without code?

I have looked for information about it, and I see that code is used. There is no sensible way to do it? I have seen the CURDATE () function, but I would not know how to use it to be inserted automatically in a Date field of a table, every time I create a new record.

Thank you!
Dreamer.-
Last edited by DreamerArgentino on Tue May 22, 2018 4:39 am, edited 1 time in total.
OpenOffice 4.1.5 On Windows 10
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Create field that automatically stamps the current date?

Post by UnklDonald418 »

To add a Timestamp column that
automatically stamps the current date without code
edit the following SQL command with your table and column/field names

Code: Select all

ALTER TABLE "YourTableName" ADD COLUMN "YourColumnName" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP;
and then got to Tools->SQL and execute the command.
You should also select View->Refresh tables to make sure you can see the change to your table.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
DreamerArgentino
Posts: 17
Joined: Sun May 20, 2018 12:02 am

Re: Create field that automatically stamps the current date?

Post by DreamerArgentino »

UnklDonald418 wrote:To add a Timestamp column that
automatically stamps the current date without code
edit the following SQL command with your table and column/field names

Code: Select all

ALTER TABLE "YourTableName" ADD COLUMN "YourColumnName" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP;
and then got to Tools->SQL and execute the command.
You should also select View->Refresh tables to make sure you can see the change to your table.
It works wonders! but, I ask, will it be possible to generate two separate fields in the same way? One Date and another Time? Thanks!
OpenOffice 4.1.5 On Windows 10
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Create field that automatically stamps the current date?

Post by UnklDonald418 »

You can add separate Date and Time controls to a form using the TimeStamp column as the Data source.
One way to separate them in a query use

Code: Select all

TO_CHAR("YourTimeStampColumnName", 'MM/DD/YYYY') AS "Date",
TO_CHAR("YourTimeStampColumnName", 'HH24:MI:SS:FF') AS "Time"
If you don't need all the time accuracy you could change the time formatting to 'HH24:MI' or maybe 'HH12:MI'
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Sliderule
Volunteer
Posts: 1279
Joined: Thu Nov 29, 2007 9:46 am

Re: Create field that automatically stamps the current date?

Post by Sliderule »

DreamerArgentino wrote:It works wonders! but, I ask, will it be possible to generate two separate fields in the same way? One Date and another Time? Thanks!

Code: Select all

-- Code below will add a DATE column and a DEFAULT DATE . . . change both table and column name to your needs
ALTER TABLE "YourTableName" ADD COLUMN "YourDateColumnName" DATE DEFAULT CURRENT_DATE;


-- Code below will add a TIME column and a DEFAULT TIME . . . change both table and column name to your needs
ALTER TABLE "YourTableName" ADD COLUMN "YourTimeColumnName" TIME DEFAULT CURRENT_TIME;


-- Code below will add a TIMESTAMP column and a DEFAULT TIMESTAMP . . . change both table and column name to your needs
ALTER TABLE "YourTableName" ADD COLUMN "YourTimeStampColumnName" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP;
Sliderule
DreamerArgentino
Posts: 17
Joined: Sun May 20, 2018 12:02 am

Re: Create field that automatically stamps the current date?

Post by DreamerArgentino »

Sliderule wrote:
DreamerArgentino wrote:It works wonders! but, I ask, will it be possible to generate two separate fields in the same way? One Date and another Time? Thanks!

Code: Select all

-- Code below will add a DATE column and a DEFAULT DATE . . . change both table and column name to your needs
ALTER TABLE "YourTableName" ADD COLUMN "YourDateColumnName" DATE DEFAULT CURRENT_DATE;


-- Code below will add a TIME column and a DEFAULT TIME . . . change both table and column name to your needs
ALTER TABLE "YourTableName" ADD COLUMN "YourTimeColumnName" TIME DEFAULT CURRENT_TIME;


-- Code below will add a TIMESTAMP column and a DEFAULT TIMESTAMP . . . change both table and column name to your needs
ALTER TABLE "YourTableName" ADD COLUMN "YourTimeStampColumnName" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP;
Sliderule
Excellent!! Thank you very much to all!!!
Greetings!
DreamerArg.-
OpenOffice 4.1.5 On Windows 10
Post Reply