freecrm
New Member
- Messages
- 629
- Reaction score
- 0
- Points
- 0
After spending a week on this and not really getting anywhere, I need this fixed which is why I'm offering 500.
Platform: php on MySQL
Site: www.freecrm.x10hosting.com
Process for: Event management
AIM
1) User 1 in GB timezone (UTC+01:00) enters a date/time string, assisted by a JS datetime picker that returns a "Y-m-d H:i:s" format. I will call this value "exampledate"
The value is either inserted or updated to a table.
2) User 2 in US/Central timezone echo's the exampledate and sees the date relative to his timezone - i.e. -06:00 in a format which he/she has set in their preferences.
CURRENT VARIABLES & SETTINGS
Only users can enter dates adn each user can set their timezone and timeformat preferences which are loaded on login and carried as session variables
$_SESSION['MM_UTZ'] and $_SESSION['MM_UTF']
In each page header, I have the following include:
session_start();
//set page timezone
if ($_SESSION['MM_UTZ'] == NULL){
$_SESSION['MM_UTZ']="UTC";}
putenv ("TZ=".$_SESSION['MM_UTZ']);
//set page timeformat
if ($_SESSION['MM_UTF'] == NULL){
$_SESSION['MM_UTF']="Y-m-d H:i:s";
}
If there is no preference, it will set UTC and Y-m-d H:i:s as default values and assign $_SESSION['MM_UTZ'] to the default server timezone (I think... although I'm not clear if I should use the date_default_timezone_set() function).
THE INSERT PART
From a form field (which I shall call timefield), I am currently trying to convert the date/time string using new DateTime() to store.
$dto_timefield= new DateTime($_POST['timefield'], new DateTimeZone($_SESSION['MM_UTZ']));
I can then use this to insert
i.e. INSERT INTO EVENTS (EVSTART) VALUES ($dto_timefield->format(DATE_RFC3339))
If I echo this, it will return something like this.
08-09-02T22:07:31+01:00
I am then trying to store this is a VARCHAR MySQL field...
THE RESULTS PAGE
Not doing well here...
User 2 looks at this data in a different timezone from, say, a recordset.
How do I get this result to account for the difference in timezones??
strtotime??
mktime???
Another new DateTime object?
As you can see, I'm serious about getting this done so please - any help will be appreciated - even if you have a different approach.
Platform: php on MySQL
Site: www.freecrm.x10hosting.com
Process for: Event management
AIM
1) User 1 in GB timezone (UTC+01:00) enters a date/time string, assisted by a JS datetime picker that returns a "Y-m-d H:i:s" format. I will call this value "exampledate"
The value is either inserted or updated to a table.
2) User 2 in US/Central timezone echo's the exampledate and sees the date relative to his timezone - i.e. -06:00 in a format which he/she has set in their preferences.
CURRENT VARIABLES & SETTINGS
Only users can enter dates adn each user can set their timezone and timeformat preferences which are loaded on login and carried as session variables
$_SESSION['MM_UTZ'] and $_SESSION['MM_UTF']
In each page header, I have the following include:
session_start();
//set page timezone
if ($_SESSION['MM_UTZ'] == NULL){
$_SESSION['MM_UTZ']="UTC";}
putenv ("TZ=".$_SESSION['MM_UTZ']);
//set page timeformat
if ($_SESSION['MM_UTF'] == NULL){
$_SESSION['MM_UTF']="Y-m-d H:i:s";
}
If there is no preference, it will set UTC and Y-m-d H:i:s as default values and assign $_SESSION['MM_UTZ'] to the default server timezone (I think... although I'm not clear if I should use the date_default_timezone_set() function).
THE INSERT PART
From a form field (which I shall call timefield), I am currently trying to convert the date/time string using new DateTime() to store.
$dto_timefield= new DateTime($_POST['timefield'], new DateTimeZone($_SESSION['MM_UTZ']));
I can then use this to insert
i.e. INSERT INTO EVENTS (EVSTART) VALUES ($dto_timefield->format(DATE_RFC3339))
If I echo this, it will return something like this.
08-09-02T22:07:31+01:00
I am then trying to store this is a VARCHAR MySQL field...
THE RESULTS PAGE
Not doing well here...
User 2 looks at this data in a different timezone from, say, a recordset.
How do I get this result to account for the difference in timezones??
strtotime??
mktime???
Another new DateTime object?
As you can see, I'm serious about getting this done so please - any help will be appreciated - even if you have a different approach.