This topic is locked

Preset Current Date Not Correct

9/22/2020 11:09:33 PM
PHPRunner General questions
F
fsyeung author

I using the now() in the field for preset the current date & time, but the data is show in yesterday (one day before). What is wrong and how to solve.

Sergey Kornilov admin 9/23/2020

now() will use the date based on the timezone specified in php.ini file on the webserver. You either need to change the timezone in php.ini or use the following function to change the default timezone in your AfterAppInit event:

https://www.php.net/manual/en/function.date-default-timezone-set.php

M
Mark Kramer 9/24/2020



I using the now() in the field for preset the current date & time, but the data is show in yesterday (one day before). What is wrong and how to solve.


I create a demographics table something like this. Name, Address, Phone, Timezone, etc....
I also create a timezone table and populate it with the data found here https://www.php.net/manual/en/timezones.php
I use the timezone table to populate the "Timezone" field in the demographics table.
Once that is set up in the "after application initialized" event I add this code:
global $dal;

$tblpropertyinfo=$dal->Table("Your demographics Table goes here");
$rs = $tblpropertyinfo->QueryAll();
while ($data = db_fetch_array($rs))
$TimeZone.=$data["Timezone"];
date_default_timezone_set($Timezone);
The reason I do it this way is so I can change timezones for each property location and it's reletive time zone... In other words if Comapny A uses a copy of the program in EST and and Comapny B uses another instance of the porgram in Central timezone just a change in the Demographice table record is all you need... I hope that made sense. There is another question in this forum using users location which is very similar to my approach,
Hope it helps <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=92683&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
mk