Have you ever experienced something strange when creating the web applications that generated by PHPMaker which use multi-language and the Timezone is other than GMT? If you look closely at the Date and Time when the data from the database is displayed, then the value will be converted twice from the original GMT Date and Time. Still confused what I meant? Let's take a look at the example below.
The Timezone that you use both for the web application and the web server is Asia/Jakarta (GMT+7), and the Date and Time of data is saved to the server correctly according to the date and time when user input the data as 2013-07-25 10:48:30. When this data is displayed on the List and View pages, then it will be displayed as 2013-07-25 17:48:30. I think this explanation is clear enough now.
To fix the problem, then I will show you how you can overcome this issue easily using Server Events of PHPMaker. So, in that case above, it will be displayed as 2013-07-25 10:48:30.
- Open your PHPMaker project (.pmp) file using PHPMaker application.
Click on your desired table from the Database pane in the left side, then click on Code (Server Events, Client Scripts and Custom Templates) tab, and then expand the following section: Server Events -> Table-Specific -> List Page -> ListOptions_Load function, and then insert the following code into the function:
// This will get the original value of datetime value from any datetime field database // since the Regional Settings in server is "Bangkok (GMT+7)" and the timezone setting // in .xml language file is "Asia/Jakarta". // If we don't change the default timezone to GMT, then the datetime that will be displayed // in the List page will always GMT+7. So strange, right? date_default_timezone_set("GMT");
This will convert the data back to the real one when it is displayed in the List page.
- Do the previous step also for the following section: Server Events -> Table-Specific -> View Page -> Page_Load function. Make sure you do not miss this step since this will convert the data back to the real one when it is displayed in the View page.
- Finally, re-generate your script files using PHPMaker as always. 🙂