如何在 MySQL 查询中根据美国时区显示日期时间?
How to show datetime according to US timezone in MySQL query?
我是 MySQL 查询和存储过程的新手。我在印度工作,我想要美国的时区。为此,我正在使用
set currTimeStamp = date(UTC_TIMESTAMP + interval 5 hour + interval 30 minute);
set currDate = date(UTC_DATE() + interval 5 hour + interval 30 minute);
-- insert into oc_product
insert into oc_product (model, ean, jan, isbn,mpn,location, stock_status_id,manufacturer_id,tax_class_id, date_available,
date_added,date_modified, image, weight, length, width, height, upc, price, sku, from_edi )
SELECT '','','','','','','','','',currDate, currTimeStamp , currTimeStamp , w.image, w.weight, w.length, w.width,
w.height, w.upc, w.price, w.sku, 1 FROM tmp_product_insert as w left join oc_product as ocp on (ocp.sku <> w.sku
and ocp.from_edi=1) where ocp.product_id IS NULL;
当我尝试在本地数据库中打印时,它显示
date(UTC_TIMESTAMP + interval 5 hour + interval 30 minute)
2020-07-13
但我想要 2020-07-13 15:15:30
格式。
对于 currTimeStamp
变量,我们需要 yyyy-mm-dd h:i:s
格式,对于 currdate
变量,我们需要 yyyy-mm-dd
格式。我们如何在查询中得到这个?
您使用的 date
类型明确地 只是 一个日期,没有时间。使用 datetime
.
我是 MySQL 查询和存储过程的新手。我在印度工作,我想要美国的时区。为此,我正在使用
set currTimeStamp = date(UTC_TIMESTAMP + interval 5 hour + interval 30 minute);
set currDate = date(UTC_DATE() + interval 5 hour + interval 30 minute);
-- insert into oc_product
insert into oc_product (model, ean, jan, isbn,mpn,location, stock_status_id,manufacturer_id,tax_class_id, date_available,
date_added,date_modified, image, weight, length, width, height, upc, price, sku, from_edi )
SELECT '','','','','','','','','',currDate, currTimeStamp , currTimeStamp , w.image, w.weight, w.length, w.width,
w.height, w.upc, w.price, w.sku, 1 FROM tmp_product_insert as w left join oc_product as ocp on (ocp.sku <> w.sku
and ocp.from_edi=1) where ocp.product_id IS NULL;
当我尝试在本地数据库中打印时,它显示
date(UTC_TIMESTAMP + interval 5 hour + interval 30 minute)
2020-07-13
但我想要 2020-07-13 15:15:30
格式。
对于 currTimeStamp
变量,我们需要 yyyy-mm-dd h:i:s
格式,对于 currdate
变量,我们需要 yyyy-mm-dd
格式。我们如何在查询中得到这个?
您使用的 date
类型明确地 只是 一个日期,没有时间。使用 datetime
.