View Full Version : create field that auto populates with record creation date/time?


lmp1
02-11-2008, 04:27 PM
I think my question is fairly simple - fingers crossed.

I want to create a field that, whenever a record is added, it auto-adds the date & time the record was created. I'd call it Book_Date_Added, or something like that. I tried snooping around the Default Value options but couldn't figure it out.

The table exists and it already has some records, so I'd need to know how to add this field rather than how to create it when I create a table (although that would be helpful too, if it's somehow different).

I'd appreciate any help, thanks a bunch.

tehNellie
02-11-2008, 05:01 PM
If you create a column as a date/time datatype and use a default value of now(). Anytime you don't specify that column when you add a new row it will insert the current datetime as a default value.

If you add the column to an existing table any rows already present will be populated with NULL so you might want to consider using an UPDATE query to add a default time stamp to existing records whether that is the current date/time or some other default date/time. I tend to pad 01/01/1900 00:00:00 when I need a placeholder date and dont want a NULL value, but only because in my tables that date is never "valid".

lmp1
02-11-2008, 08:12 PM
Thank you, that worked like a charm. Apparently I just didn't know the correct syntax to use there.

As a follow-up question, since I'm a novice, I'm wondering - what does putting the () do? Why can't I just put NOW w/o them? Just curious, not crucial, but hoping it will help me figure out stuff myself later on.

Thanks again.

tehNellie
02-12-2008, 01:47 AM
The brackets basically indicate it's a function. If you omit them in the table design Access will assume you want the now() function and add them automatically. If you wanted to use "now" as a text value you'd need to wrap it quotes to disintinguish it from the function.