CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [SOLVED] change php and mysql timezone

Print topic Send  topic

Author Message
erdcck


Posts: 17
Posted: 08/13/2014, 10:20 AM

Dear friends and saseow :)

My customers using our application from different countries. Every customer adding own records. Application have a hidden control for adding current time.
Actually all record time same. because codecharge getting date and time from server. How can I get customer local date and time in hidden control?

thank you so much
View profile  Send private message
saseow

Posts: 744
Posted: 08/13/2014, 10:53 AM

The timezone will always be the server's timezone so, you have to change that to the user's timezone.
Have a look at the following and I am sure you can sort it out:

http://www.pontikis.net/tip/?id=18

This is a good example of doing it:
http://stackoverflow.com/questions/470617/get-current-date-and-time-in-php

By reading up on it you always learn better than simply having code given. Have fun!
View profile  Send private message
erdcck


Posts: 17
Posted: 08/14/2014, 12:19 AM

Dear saseow thank you so much , I did it .

Step one = I created one mysql table, table name zone. and import zone names in table. (zone file csv http://turbobit.net/b2ll3klpzdnh.html)

step two = Add timezone selector (listbox) customers settings page.

step tree = add following custom code for hidden control ( I change hidden properties date to text)

	  
$db = new clsDBxxxDB;  
$timezone_name = ccdlookup("timezone_name","companies","company_id=".CCGetSession("company_id",""), $db);  
  
    date_default_timezone_set($timezone_name);  
    $date = date('Y/m/d H:i:s', time());  
    $jobs1->job_added_date->SetValue($date);  
      
    $db->close();
View profile  Send private message
saseow

Posts: 744
Posted: 08/14/2014, 1:35 AM

Excellent! That;s the way to go.
View profile  Send private message
erdcck


Posts: 17
Posted: 08/14/2014, 2:24 AM

Thank you saseow

I changed globaly timezone. I added following code in Common.php (end line)

	  
	$db = new clsDBxxxxDB;  
	$timezone_name = ccdlookup("timezone_name","companies","company_id=".CCGetSession("company_id",""), $db);  
    if ($timezone_name <> ""){  
    	date_default_timezone_set($timezone_name);  
    }  
    $db->close();  
  
View profile  Send private message
erdcck


Posts: 17
Posted: 08/14/2014, 6:37 AM

Dear saseow I have a problem :)
Php timezone settings okay no problem everything fine.
I want to change mysql timezone for customers like a php. How Can I do.
After adding the customer's own record. Not showing in todays records in grid.

Because
mysql timezone = Europe/Istanbul.
php timezone = Pacific/Fiji.

I used following code but not work.

 mysql_query("SET time_zone = '".date_default_timezone_get()."';"); 

I m waiting for your help. thank you.
View profile  Send private message
saseow

Posts: 744
Posted: 08/14/2014, 9:03 PM

I do not think that it is possible to do this unless you own the server. However, I am not 100% sure about this.
Have a look at these two pages:

http://stackoverflow.com/questions/13916747/set-mysql-d...timezone-to-gmt

http://stackoverflow.com/questions/3451847/mysql-timezone-change

Sorry, I cannot help with this one.
View profile  Send private message
icp4all

Posts: 37
Posted: 08/15/2014, 4:12 PM

Thats just simple (in theory)
You must store all times in a timestamp (Server Time!)
Now you only need the Users local time (must be stored in the user's profile).
I used the PHP function.
And now you can calculate the difference !!!
Everytime a User adds a record, your form retrieves the difference from the user record and store the (user)time in the db...
For all displayed Dates you have to calculate the time in the same way

so IE
user adds a date
before insert - > retrieve User time zone -> Add/subtract the difference and store the (calculated time) to DB
User opens a List, Grid, receive a email or what ever
before Show - > retrieve User time zone -> Add/subtract the difference and store the calculateed time
to the variable in your form
BTW if a user travels from IE from Europe to China.. he just need to change his timezone in his profile and all dates will be shown in the new local (here china time)

hope this helps a little bit...

I made an event planer for an international Gaming clan, and it works fine

but it took 3 or 4 days to manage the problem with ccs
View profile  Send private message
erdcck


Posts: 17
Posted: 08/18/2014, 6:49 AM

Dear friends thank you so much for your posts.

I solved the problem.

--------------------------- CHANGE PHP DEFAULT TIME ZONE -- SET TIMEZONE SESSION ------------------------------------
Step one = I created one mysql table, table name zone. and import zone names in table. (zone file csv http://turbobit.net/b2ll3klpzdnh.html)
Step two = Add timezone selector (listbox) customers settings page.
Step tree = add following code to commom.php

  
	$db = new clsDBmyprintDB;  
	$timezone_name = ccdlookup("timezone_name","companies","company_id=".CCGetSession("company_id",""), $db);  
    if ($timezone_name <> ""){  
    	date_default_timezone_set($timezone_name);  
    	CCSetSession("TimeZone", "$timezone_name");   // timezone name example 'Pacific/Fiji'   
    }  
    $db->close();  

---------------------- GET RECORDS SQL QUERY WITH CONVERT_TZ --------------------------------


  
SELECT *   
FROM (jobs INNER JOIN customer ON  
jobs.is_customer_id = customer.customer_id) INNER JOIN job_status ON  
jobs.is_durumu = job_status.job_status_id  
WHERE jobs.company_id = {company_id} AND datediff(is_teslim_tarihi, CONVERT_TZ(NOW(), @@global.time_zone, '{TimeZone}')) between 0 and 0  
ORDER BY job_status_id = 5 DESC, customer_id  


View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.