WebSite X5Help Center

 
Ray W.
Ray W.
User

How to add hidden datestamp to database using the Contact Form obj?  en

Autor: Ray W.
Besucht 343, Followers 1, Geteilt 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.


Gepostet am
14 ANTWORTEN - 3 NüTZLICH
Ray W.
Ray W.
User
Autor

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.

Mehr lesen
Gepostet am von Ray W.
John S.
John S.
User

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.

Mehr lesen
Gepostet am von John S.
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator
Nutzer des Monats PL
Ray W.
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.

... (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

.

Mehr lesen
Gepostet am von  ‪ KolAsim ‪ ‪
Ray W.
Ray W.
User
Autor

Hi John,

Thanks for your help.

Mehr lesen
Gepostet am von Ray W.
Ray W.
Ray W.
User
Autor

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

Mehr lesen
Gepostet am von Ray W.
Ray W.
Ray W.
User
Autor

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


Mehr lesen
Gepostet am von Ray W.
Ray W.
Ray W.
User
Autor

I just checked UTC time and it does look like the database is correctly reporting UTC time.

Mehr lesen
Gepostet am von Ray W.
Ray W.
Ray W.
User
Autor

So if the server UTC time is correct, is it possible your PHP server-settings are not using UTC time?

Mehr lesen
Gepostet am von Ray W.
Ray W.
Ray W.
User
Autor

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.

Mehr lesen
Gepostet am von Ray W.
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator
Nutzer des Monats PL
Ray W.
... ... ...  Can you send me your extra code please? ... ... ... 

...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
.

Mehr lesen
Gepostet am von  ‪ KolAsim ‪ ‪
Incomedia
Eric C.
Incomedia

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.

Mehr lesen
Gepostet am von Eric C.
Ray W.
Ray W.
User
Autor

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.


Mehr lesen
Gepostet am von Ray W.
Ray W.
Ray W.
User
Autor

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.

Mehr lesen
Gepostet am von Ray W.