MySQL CONVERT_TZ()函数相关问题

时间:2014-08-17 06:05:33

标签: php mysql

以下代码用于获取当周的上周六和下周六

// GET Last Satuday of current week
$dt_week_start_time = strtotime("last saturday")+((20*3600)+ 1);
$dt_week_start_date = date('Y-m-d G:i:s', $dt_week_start_time);

// GET Last Satuday of current week
$dt_week_end_time = $dt_week_start_time + (7*3600*24) - 1;
$dt_week_end_date = date('Y-m-d G:i:s', $dt_week_end_time);

以下代码用于将上述日期相关变量转换为EST时区(默认时区为UTC)

$est_time = new DateTimeZone('EST');

$datetime = new DateTime($dt_week_start_date);
$datetime->setTimezone($est_time);
$dt_week_start_date = $datetime->format('Y-m-d G:i:s');

$datetime = new DateTime($dt_week_end_date);
$datetime->setTimezone($est_time);
$dt_week_end_date = $datetime->format('Y-m-d G:i:s');

现在我想将这些EST时区日期与mySQL数据库表中的日期进行比较。默认情况下,mySQL数据库表中的日期存储在UTC时区中。通过互联网研究,有人建议使用CONVERT_TZ功能。我尝试了但是它给出了如下所述的错误

我的查询有什么问题?请指教。

以下2个查询发出此错误:'注意:未定义索引:purchaseatetime ...'

$str_query_select = "SELECT CONVERT_TZ(purchasedatetime, 'UTC', 'EST' ) FROM t_product_purchase WHERE sellerpkid=1";

$str_query_select = "SELECT CONVERT_TZ((SELECT purchasedatetime FROM t_product_purchase),'UTC','EST') FROM t_product_purchase WHERE sellerpkid=1";

0 个答案:

没有答案