Ask Your Question
0

Insert the current date and current time into a new database record? [closed]

asked 2014-03-22 20:58:41 +0100

Ronnie James Dio Fan gravatar image

I want to have the current date and time inserted into separate fields in a database record when a new record is written. How do I do this?

Thanks in advance!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-02-20 08:43:49.751729

1 Answer

Sort by » oldest newest most voted
0

answered 2014-03-24 05:13:04 +0100

frofa gravatar image

updated 2014-03-24 05:14:26 +0100

You will need first to have (or create) SEPARATE columns for Date (must be 'Date' type) and Time (must be 'Time' type) in your table - I'm calling your table Dates_Times but you will need to change it to whatever you have called it in the code below. Then you have to set the defaults for each of these columns by running each of the two SQL statements below (separately) from the SQL window (menu: TOOLS>SQL):

ALTER TABLE "Dates_Times" ALTER COLUMN "Date" SET DEFAULT CURRENT_DATE
ALTER TABLE "Dates_Times" ALTER COLUMN "Time" SET DEFAULT CURRENT_TIME

You should see a "Command successfully executed" message after each command is run.

Then, every time you add a new record, the current values of Date and Time will be added (you might need to 'refresh' the table to see them). However note, the date and time values will NOT be updated whenever you update a particular row/record (that's a different problem).

edit flag offensive delete link more

Comments

Thank you very much!

Ronnie James Dio Fan gravatar imageRonnie James Dio Fan ( 2014-03-24 21:46:43 +0100 )edit

I really appreciate your consise answer to the question above. I had the same current-date question. After inserting the first line of SQL above, the current date appeared upon entering a new record in the table.

Hoping to be able to contribute toward the "answer" portion of this website someday, I will use this site and look for your answers to BASE questions as I go through the process of learning a data base system after years of spreadsheet dependence in our family business.

grandma gravatar imagegrandma ( 2014-07-22 19:15:21 +0100 )edit

Question Tools

2 followers

Stats

Asked: 2014-03-22 20:58:41 +0100

Seen: 9,534 times

Last updated: Mar 24 '14