This topic is locked
[SOLVED]

 Show London/uk Time, Not Server Time.

1/30/2013 4:07:29 PM
PHPRunner General questions
H
herb200mph author

Using the date coding below, how do we code the date to show "now" London/UK time when saved/submitted action takes place?
CustomQuery("update ApplicationForm set DateField=now() where ID=".$key_str);
The date display is the local time of the server (Eastern USA), but should be London/UK.
We cannot change the php.ini file, or can we create one in the project directory that will fire the correct time for London/UK.

C
cgphp 1/30/2013
$offset = get_timezone_offset('Europe/London');

$offset_time = time() + $offset;

$date = date('Y-m-d h:i:s', $offset_time);

$rs = CustomQuery("UPDATE ApplicationForm SET DateField = '".$date."' WHERE ID = ".$key_str);


Make sure you areusing a PHP version >= 5.2

H
herb200mph author 1/30/2013

Thanks.
The full event code for "server" is this. Where does the code you graciously provided go?
= = = = =

global $dal;

$dal_table = $dal->table("ApplicationForm"); $key_str = ""; for ($i=0; $i<count($keys); $i++) $key_str.= $keys[$i]["ID"].","; if ($key_str) $key_str = substr($key_str,0,-1);
if ($key_str && count($keys)==1){
$rstmp = $dal_table->Query("ID=".$key_str,"");

$datatmp = db_fetch_array($rstmp);

if (!$datatmp["DateField"]){
ExportToCSV($key_str);
createRTF($key_str);
$message = CustomSendEmail($key_str);
if ($message=="sent")

$result["txt"] = "<br/><div class=greentext><b>Application Submission Information and<br/>Notification has been Sent to the Trust.</b></div><br/><br/>";

else $result["txt"] = $message; }

//update table

CustomQuery("update ApplicationForm set DateField=now() where ID=".$key_str);

//where DateField is your actual field name

} else $result["txt"] = "<br/><div class=indenttext><b class=redtext>NOTICE!</b><BR><hr><b class=redtext>You must select one Grant Application from<br/>list below to submit to the Trust.</b><br/><br/><b class=bluetext>SELECT ONLY ONE APPLICATION PER SUBMISSION ACTION!</b>

<b class=redtext>DO NOT SUBMIT THE APPLICATION WITHOUT THE NECESSARY ATTACHMENTS!</b>

</div><br/><br/>";

C
cgphp 1/30/2013
global $dal;

$dal_table = $dal->table("ApplicationForm"); $key_str = ""; for ($i=0; $i<count($keys); $i++) $key_str.= $keys[$i]["ID"].","; if ($key_str) $key_str = substr($key_str,0,-1);
if ($key_str && count($keys)==1){
$rstmp = $dal_table->Query("ID=".$key_str,"");

$datatmp = db_fetch_array($rstmp);

if (!$datatmp["DateField"]){
ExportToCSV($key_str);
createRTF($key_str);
$message = CustomSendEmail($key_str);
if ($message=="sent")

$result["txt"] = "<br/><div class=greentext><b>Application Submission Information and<br/>Notification has been Sent to the Trust.</b></div><br/><br/>";

else $result["txt"] = $message; }

//update table

$offset = get_timezone_offset('Europe/London');

$offset_time = time() + $offset;

$date = date('Y-m-d h:i:s', $offset_time);

$rs = CustomQuery("UPDATE ApplicationForm SET DateField = '".$date."' WHERE ID = ".$key_str);

//where DateField is your actual field name

} else $result["txt"] = "<br/><div class=indenttext><b class=redtext>NOTICE!</b><BR><hr><b class=redtext>You must select one Grant Application from<br/>list below to submit to the Trust.</b><br/><br/><b class=bluetext>SELECT ONLY ONE APPLICATION PER SUBMISSION ACTION!</b>
<b class=redtext>DO NOT SUBMIT THE APPLICATION WITHOUT THE NECESSARY ATTACHMENTS!</b>

</div><br/><br/>";
H
herb200mph author 1/30/2013

Thanks for the code change.
Unfortunately, it did not change the way the time is displayed. Still USA/Eastern.

C
cgphp 1/30/2013

What is the version of PHP you are using?

H
herb200mph author 1/30/2013



What is the version of PHP you are using?


Using PHP 5.3.15 on Xlinesoft's server.

C
cgphp 1/30/2013

Check this version:

global $dal;

$dal_table = $dal->table("ApplicationForm"); $key_str = ""; for ($i=0; $i<count($keys); $i++) $key_str.= $keys[$i]["ID"].","; if ($key_str) $key_str = substr($key_str,0,-1);
if ($key_str && count($keys)==1){
$rstmp = $dal_table->Query("ID=".$key_str,"");

$datatmp = db_fetch_array($rstmp);

if (!$datatmp["DateField"]){
ExportToCSV($key_str);
createRTF($key_str);
$message = CustomSendEmail($key_str);
if ($message=="sent")

$result["txt"] = "<br/><div class=greentext><b>Application Submission Information and<br/>Notification has been Sent to the Trust.</b></div><br/><br/>";

else $result["txt"] = $message; }

//update table

$d = new DateTime();

$d->setTimezone(new DateTimeZone('Europe/London'));

$date = $d->format('Y-m-d H:i:s');

$rs = CustomQuery("UPDATE ApplicationForm SET DateField = '".$date."' WHERE ID = ".$key_str);

//where DateField is your actual field name

} else $result["txt"] = "<br/><div class=indenttext><b class=redtext>NOTICE!</b><BR><hr><b class=redtext>You must select one Grant Application from<br/>list below to submit to the Trust.</b><br/><br/><b class=bluetext>SELECT ONLY ONE APPLICATION PER SUBMISSION ACTION!</b>
<b class=redtext>DO NOT SUBMIT THE APPLICATION WITHOUT THE NECESSARY ATTACHMENTS!</b>

</div><br/><br/>";
H
herb200mph author 1/30/2013

That did not work either.
Still generating USE/Eastern time stamp.

C
cgphp 1/30/2013

Just tested my code on the Xlinesoft server and works fine:

$d = new DateTime();

$d->setTimezone(new DateTimeZone('Europe/London'));

echo $d->format('Y-m-d H:i:s');


Make sure you are executing/checking the right section of your application.

H
herb200mph author 1/30/2013

That code was supplied by PHPR and it is working OK.
It is in an event for the LIST page as a "server" event of a submit button.
We added a separate button on the LIST page that fires the event code to submit the record, CSV, RTF, attachments to admin via email.
Let me give it a try again.

H
herb200mph author 1/30/2013

NOPE. Shooting USA/Eastern again.

H
herb200mph author 1/30/2013

What should the field properties be?
We have it as TextField and Datetime.

C
cgphp 1/30/2013

Check if the date was saved correctly to the database.

H
herb200mph author 1/30/2013

Data field in the database is showing the time as USA/Eastern with the code you provided.

C
cgphp 1/30/2013

Are you from UK or from USA? Try to run the following code as a standalone script on your localhost:

$d = new DateTime();

$d->setTimezone(new DateTimeZone('Europe/London'));

echo $d->format('Y-m-d H:i:s');
H
herb200mph author 1/30/2013

Cristian:
What time display did you get when you tried it.
It's 22:50 in London right now.

H
herb200mph author 1/30/2013

Worked just fine, display as "2013-01-30 22:51:49" in a PHP file on the same server in the same directory as the project.
Go figure that one out!!!! LOLOLLL
Wonder what the issue is with it not triggering correctly within the code.

H
herb200mph author 1/30/2013

PHPR Support offered up this:
date_default_timezone_set('Europe/London');
for the AfterApplicationInitialized event.
IT WORKED!!!
That seemed to resolved the issue, along with the great code you provided.
Leaving both in place, as is, because if it works, it don't need fixin'
Thanks for the great help with this problem, and others in the past.
HERB

H
herb200mph author 1/30/2013

Off to dinner with spouse.
Thanks again for your help.

H
herb200mph author 1/31/2013

Cristian:
Wanted to thank you again for the help last evening.
I had to leave on short notice = spouse wanted to go out for dinner.
So, please accept my belated "THANKS" for your assistance.
HERB

C
cgphp 1/31/2013

Thanks.

H
herb200mph author 1/31/2013

Three questions:
1)Where are you located?
2)Are you available for PHPR tasks on occasion?
3)Typical rates for work?
You can connect with me directly at 200mph@200mphmedia.net if you do not wish to post answers to the questions here.
HERB