[Solved] Create field that automatic stamps Current Date?

Creating tables and queries

[Solved] Create field that automatic stamps Current Date?

Postby DreamerArgentino » Mon May 21, 2018 5:58 pm

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
DreamerArgentino
 
Posts: 17
Joined: Sun May 20, 2018 12:02 am

Re: Create field that automatically stamps the current date?

Postby UnklDonald418 » Mon May 21, 2018 6:32 pm

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   Expand viewCollapse view
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1179
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Create field that automatically stamps the current date?

Postby DreamerArgentino » Tue May 22, 2018 1:21 am

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   Expand viewCollapse view
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
DreamerArgentino
 
Posts: 17
Joined: Sun May 20, 2018 12:02 am

Re: Create field that automatically stamps the current date?

Postby UnklDonald418 » Tue May 22, 2018 2:50 am

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   Expand viewCollapse view
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1179
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Create field that automatically stamps the current date?

Postby Sliderule » Tue May 22, 2018 4:08 am

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   Expand viewCollapse view
-- 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
User avatar
Sliderule
Volunteer
 
Posts: 1171
Joined: Thu Nov 29, 2007 9:46 am

Re: Create field that automatically stamps the current date?

Postby DreamerArgentino » Tue May 22, 2018 4:37 am

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   Expand viewCollapse view
-- 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
DreamerArgentino
 
Posts: 17
Joined: Sun May 20, 2018 12:02 am


Return to Tables & Queries

Who is online

Users browsing this forum: No registered users and 6 guests