Page 1 of 1

[Solved] Create field that automatic stamps Current Date?

PostPosted: Mon May 21, 2018 5:58 pm
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.-

Re: Create field that automatically stamps the current date?

PostPosted: Mon May 21, 2018 6:32 pm
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   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.

Re: Create field that automatically stamps the current date?

PostPosted: Tue May 22, 2018 1:21 am
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   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!

Re: Create field that automatically stamps the current date?

PostPosted: Tue May 22, 2018 2:50 am
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   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'

Re: Create field that automatically stamps the current date?

PostPosted: Tue May 22, 2018 4:08 am
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   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

Re: Create field that automatically stamps the current date?

PostPosted: Tue May 22, 2018 4:37 am
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   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.-