freecrm
New Member
- Messages
- 629
- Reaction score
- 0
- Points
- 0
I have numerous databases, all of which use timestamp format date/times, which are easy to echo according to user timezone preferences using putenv ("TZ=".$_SESSION['MM_UTZ']); and echo date($_SESSION['MM_UTF'], ($whatever));
The only problem is, I have only used these for stamping "date created" or "date edited" values using Time()
What I am trying to achieve is:
User 1 in UK enters date and time, using a javascript datetime picker (which normally enters data into field in Y-m-d H:i:s) and the php inserts this in timestamp format according to timezone.
User 2 in US looks at date and time and this is echo'd according to his timezone.
Sounds simple...
I have managed to get so far with the new DateTime object which incorporates the user timezone preference ($utz)
$ndttime= new DateTime($timefield, new DateTimeZone($utz));
I can then echo this effectively using
echo $ndttime->format('$utf'); ($utf being user timeformat preference)
My stupid problem is trying to get the $ndtime into the database!!!!
I know this sounds ridiculous but I use the DW insert wizard which only uses values from a form and if I echo $ndtime into a hidden field, it doesn't process this value in time.
Below is the current insert script.
Is this simple?
Heeeeelp.
Attached Code
<?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO EVENTS (EVSTART) VALUES (%s)", GetSQLValueString($_POST['evstart'], "text")); mysql_select_db($database_freecrm, $freecrm); $Result1 = mysql_query($insertSQL, $freecrm) or die(mysql_error()); $insertGoTo = "../actionconfirmed.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo));}?>
The only problem is, I have only used these for stamping "date created" or "date edited" values using Time()
What I am trying to achieve is:
User 1 in UK enters date and time, using a javascript datetime picker (which normally enters data into field in Y-m-d H:i:s) and the php inserts this in timestamp format according to timezone.
User 2 in US looks at date and time and this is echo'd according to his timezone.
Sounds simple...
I have managed to get so far with the new DateTime object which incorporates the user timezone preference ($utz)
$ndttime= new DateTime($timefield, new DateTimeZone($utz));
I can then echo this effectively using
echo $ndttime->format('$utf'); ($utf being user timeformat preference)
My stupid problem is trying to get the $ndtime into the database!!!!
I know this sounds ridiculous but I use the DW insert wizard which only uses values from a form and if I echo $ndtime into a hidden field, it doesn't process this value in time.
Below is the current insert script.
Is this simple?
Heeeeelp.
Attached Code
<?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO EVENTS (EVSTART) VALUES (%s)", GetSQLValueString($_POST['evstart'], "text")); mysql_select_db($database_freecrm, $freecrm); $Result1 = mysql_query($insertSQL, $freecrm) or die(mysql_error()); $insertGoTo = "../actionconfirmed.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo));}?>