A client of mine in Florida has a site hosted on a server in Houston, TX. He is upset that all of his reports are coming out from the database a hour off. to insert records into the database, the MySQL Function time() is used, then a standard SELECT statements get the records out of the database. Is there some easy way I can modify the INSERT statement, or the SELECT statement to use the correct time zone.
Here is where the INSERT statement is being created:
$query_rsCWAddOrder = sprintf("INSERT INTO tbl_orders
(order_ID, order_CustomerID,
order_Tax, order_Shipping, order_ShippingTax,
order_Total, order_Status,
order_ShipMeth_ID, order_Address1,
order_Address2, order_City,
order_Zip, order_Country,
order_State, order_TransactionID,
order_Date, order_ShipName, order开发者_如何学JAVA_DiscountID,
order_DiscountAmount, order_Comments)
VALUES ('%s','%s',%s,%s,%s,%s,'%s',%s,'%s','%s','%s','%s','%s','%s','%s',now(),'%s',%d, %s, '%s')",
$thisOrderID
, $_SESSION["customerID"]
, mySQLFloat($cart["CartTotals"]["Tax"] )
, str_replace('$', '', $_SESSION['SHIPPING_TOTAL'])
, mySQLFloat($cart["CartTotals"]["ShippingTax"] )
, str_replace('$', '', $_SESSION['ORDER_TOTAL'])
, 2
, $_SESSION["shipPref"] != 0 ? $_SESSION["shipPref"] : "NULL"
, addslashes($shipToStreet)
, addslashes($shipToStreet2)
, addslashes($shipToCity)
, addslashes($shipToZip)
, addslashes($row_rsCWGetCustShipping["country_Code"])
,addslashes($row_rsCWGetCustShipping["stprv_Code"])
, $transactionID
, addslashes($shipToName)
, intval($_REQUEST["shippingDiscount"])
, mySQLFloat($cart["CartTotals"]["ShippingDiscounts"])
, addslashes($_SESSION["order_Comments"]));
and here is the select statement (but there are more reports with different select statements):
$query_rsCWGetStatus = sprintf("SELECT o.order_Status, o.order_Date, c.cst_Email
FROM tbl_orders o
INNER JOIN tbl_customers c
ON c.cst_ID = o.order_CustomerID
WHERE order_ID = '%s'",$_POST["orderID"]);
From MySQL Reference:
CONVERT_TZ(dt,from_tz,to_tz)
converts a datetime valuedt
from the time zone given byfrom_tz
to the time zone given byto_tz
and returns the resulting value
In your case, you need to decide if you want to do the conversion when inserting or when querying. Since you already have data, you should change your selects:
SELECT o.order_Status, CONVERT_TZ(o.order_Date,'CST','EST'), ...
or
SELECT o.order_Status, CONVERT_TZ(o.order_Date,'-06:00','-05:00'), ...
精彩评论