PDA

View Full Version : Current date and time



adamsm
08-18-2010, 02:49 AM
Hi anyone,

I'm trying to automatically enter current data & time to the table tblCustomers when a user enters customer information to the form customers and click the next record button.

Any hep on this would be kindly appreciated.

I've attached the database for your reference.

Thanks in advance.

OBP
08-18-2010, 03:34 AM
In the field's Default Value enter
=Format(Now(),"hh:mm:ss")
For the Time and
and
=Format(Now(),"mm/dd/yyyy")
for the date.

adamsm
08-18-2010, 07:25 AM
Thanks for the help OBP. I do really appreciate your help.

adamsm
08-18-2010, 08:02 AM
I’m sorry to post back again. But there seems to be a problem when I created the Customers list form from the customers query table.

Meaning, the current time and date also gets written in the row where “New” exists even in the absence of other record columns.

Also the data rows are sorted by newest to the old.

But in the customers table the data rows are sorted by oldest to newest.

How the data rows could be adjusted by old to new in the Customers List form?

I’ve attached the current version for your reference

Any help on this would be kindly appreciated.

Thanks in advance.

HiTechCoach
08-19-2010, 01:15 PM
In the field's Default Value enter
=Format(Now(),"hh:mm:ss")
For the Time and
and
=Format(Now(),"mm/dd/yyyy")
for the date.

If the data type for the fields is Date/Time, then you should NOT use the Format() which returns a string, not a Date/Time data type.

What you are suggestion does is cause a lot of extra overhead and is not very effient.

Example:
Using the Default of =Format(Now(),"hh:mm:ss") to set the Time into a Date/time data type does this:

1) Now() returns the date and time in the date/time data type
2) Format() strips the date and formats the time as a string
3) = Nowe access must convert the string from the format back to a date/time data type.

What you should use is just: Time() without the = sign. This returns just the Time in the correct data type.

The same will hold true for the Date: Just use: Date()


@ adamsm: It is actually better/more efficient to store the date and time in a single field. Then you would use the Format() as OBP is suggesting when you want to display the Date or Time separately.

HiTechCoach
08-19-2010, 01:23 PM
I’m sorry to post back again. But there seems to be a problem when I created the Customers list form from the customers query table.

Meaning, the current time and date also gets written in the row where “New” exists even in the absence of other record columns.

Also the data rows are sorted by newest to the old.

But in the customers table the data rows are sorted by oldest to newest.

How the data rows could be adjusted by old to new in the Customers List form?

I’ve attached the current version for your reference

Any help on this would be kindly appreciated.

Thanks in advance.

You need to sort descending on the date and time fields. Note: If you use one field for both the date and time, you would only need to sort by one field.

Note: I also change the default values in the table.

See attached.