Hidden Time Field Problems

mkusens 24 Sep, 2012
I want to add a hidden field that will store just the time at the time of submit, kind of like the cf_created field does but with just the time and preferably the time of the local computer, not the server as the cf_created field does. I poured through the forums and figured out how to do this with the date field and some php code but when I tried to do it for the time field, I don't get what I expected (example: 1348458683). What do I need to do in order for the time to store properly?

Code for date field (which works perfectly)

<?php
$form->data['date'] = date('M-d-Y');
?>

Code for time field (which returns a long string of numbers)

<?php
$form->data['time'] = time('H:i:s');
?>
GreyHead 24 Sep, 2012
Hi mkusens,

PHP runs on the server so it knows nothing about the user's local computer or its timezone. You can get the current server time with date('H:i:s') - time() doesn't take any parameters and always gives you the current Unix Timestamp (the string of digits you see). Please check the PHP manual for more information.

You can probably use JavaScript in your form to add the local computer time to a hidden input in your form. But you need to be clear that you actually need that.

Bob
mkusens 24 Sep, 2012
Thanks - I used the code for the server timestamp and it worked fine. Is there a way to have the server timestamp be modified when I display it in ChronoConnectivity? So for example, the server timestamp is one hour behind the time zone of my client. Can I have the value displayed on the front end of ChronoConnectivity incremented by 1 hour for all time stamps?

By the way, purchased you a six-pack for your help.

Thanks,

Michael
GreyHead 25 Sep, 2012
Hi Michael,

Thanks for the beer, much appreciated.

There's a PHP date_default_timezone_set() function that might do what you need.

You can also set the Server timezone in the Site Global Configuration - that might set this for you.

Sorry, as you can see I don't know much about setting time-zones :-(

Bob
This topic is locked and no more replies can be posted.