How to add hidden datestamp to database using the Contact Form obj? 
Autore: Ray W.
Visite 341,
Followers 1,
Condiviso 0
Hi Guys,
How do I automaticaly add a datestamp to a database on record addition.
I want to capture the date and time a contact form submission was submitted, and include this in the database record. While I can add a date field to the Contact Form, I don't want it to modified by the person submitting the form, I want the server to add the current datestamp.
Postato il

Autore
Just like the "Posted on the 01/29/2026 21:35:13 as you see at the bottom of the text box above. I want to be able to include this in the database and also email notifcations.
In your database, you add a field of type TIMESTAMP.
Then - every record that is created, will automatically have the date+time the record was created.
Some useful links how to alter an existing table with such field.
https://stackoverflow.com/questions/155054/mysql-timestamp-column
https://dev.mysql.com/doc/refman/9.5/en/timestamp-initialization.html
You could let the contact-form create the table with the fields you want for the table.
Then make some entries in the table. This is as you would normally do.
Then you add the field TIMESTAMP to the table. You will now afterwards see the records with a date and time they were created.
... (It > En) ... ...you could use a regular date field in the contact form, and it will be placed in the database like the other entries you receive in the email...
...this date field can be automatically filled with today's date, using my own invention (an old basic example, > HERE)...
...this date field can be locked for changes, again using my EXTRA code...
...this date field, if you don't want it to be visible, can be hidden, but you'll still receive it in the email...
...if you want to go into detail with the exact code for you, let me know, and you must also post the LINK of the page with your contact form...
...if and when you do, I'll come back to you here...
.
HI, ciao
.
Autore
Hi John,
Thanks for your help.
Autore
Ok, I'm getting an error when I convert the TIMESTAMP to Loacl East Coast time. It looks like the server is not entering UTC into the TIMESTAMP field, it's 1 hour out?
Eric, if you are reading this, can you please check that your server is correctly reporting UTC time please?
thanks
Ray
Autore
Hi KolAsim, Yes I would really also like the timestamp on the email forms as well.
I have been trying the TIMESTAMP added to the table, but when I'm converting it to local time (East Coast Time) its 1 hour out, which suggests that the server TIMESTAMP time is not UTC.
I'd prefer for the field to be hidden on the form, but could not work out how to achieve that.
Can you send me your extra code please?
Sincerely
Ray
Autore
I just checked UTC time and it does look like the database is correctly reporting UTC time.
Autore
So if the server UTC time is correct, is it possible your PHP server-settings are not using UTC time?
Autore
I suspect that the server php is set to local italy time, and this is one hour off from UTC. That would result in PHP code being unable to convert to local time.
...I provided you with the basic code earlier...
...to go into more detail, as mentioned before, please post the link to your contact form page so I can evaluate...
.
Bye, ciao
.
Hello Ray,
can you tell me exactly what you set up in the database table associated to the contact form, and I will check the situation?
Thank you.
Autore
Hi Eric,
I believe that I have the table setup correctly, and it is working saving the UTC time with each record addition so I'm happy with it. <see image below>
The issue was when attempting to convert it to US East coast time using php, your PHP server setting are set to the local Rome time zone, which is 1 hour different from UTC. So to overcome this I added the following:
So instead of using:
<?php// Set your desired timezone
date_default_timezone_set('America/New_York');
I had to do the following:
<?php
$rawTime = $row['created_at'];
$dt = new DateTime($rawTime, new DateTimeZone('Europe/Rome'));
$dt->setTimezone(new DateTimeZone('America/New_York'));
$localCreatedAt = $dt->format('Y-m-d h:i A');
This fixes the time difference. Its probably because most of your customers are in Europe, that you set the php to local time rather than UTC. By convention, its usually recommended that PHP be set to use UTC.
All this means, is that folks in different time zones around the world will have to use a workaround to get accurate local time settings.
Autore
Hi Eric,
Just something to consider. It might be a good enhancement if you could automatically add the TIMESTAMP to every table, to capture time of record capture.