Hidden Date/Time field in Form?

Would like to include a hidden field in a form that would “stamp” the date and time of when the form was submitted.

Any ideas?

Ideally I would like it to be the date/time of the server the form resides on and not the date/time of the computer which it is being submited from.

Thanks in advance,
John Karben

If you can use PHP, then you can try this:

<input type=“hidden” name=“date” value=“<?php CURDATE(); ?>”>

then use another hidden field for the time.

Thanks Elledan I can us PHP and will give that a go.

For the Time is the value=“<?php CURTIME(); ?>” ?

Thanks again,
John Karben

Yes, CURTIME(); returns the time.

Oops, my bad:

The CURDATE() and CURTIME() functions are meant to be used with mySQL…

For the right PHP function, look here:

http://www.php.net/manual/en/function.getdate.php

I just came across this thread - up, I’m pretty sure (not positive) that it’s an SQL function. You’d use it in your SQL query, which works just fine anyway…time=CURTIME() - instead of time=$time, for example.

However, you can use the date function in PHP if you need the data in a hidden form field, check this out:
http://php.net/manual/en/function.date.php

Quite useful. :slight_smile:

Thanks again Elledan for the input. Unfortunately I have little knowledge at this point in writing the correct code for either PHP or mySQL. Both languages are available to me.

Would you mind taking a bit more time and writting out a suggested hidden form code for mySQL and PHP?

Thanks in advance,
John Karben

I’m confused - do you want the code for the INSERT statement using CURDATE() in SQL, or do you want the PHP code used to stick the date in a hidden form field?

If it’s the latter, which format would you like it in?

Thanks TWTCommish, I’d like the “value=” code for whichever would work best, mySQL or PHP (or both if one or the other won’t work). Please include any other code required in the .html document.

<input type=“hidden” name=“date” value=“_________”>

The PHP format prefered would be something like: month/day/time = 01/23/3:39pm or 01/23/15:39

My apologies for the confusion.

Thanks in advance,
John Karben

month/day/Year, time:

<input type=“hidden” name=“date” value=“<?php print(date(“m/d/Y, h:s A”)); ?>”>

For a month/day/time format, use this:

date(“m/d/h:s A”)