如何在mysql查询中添加时间

时间:2022-10-13 12:07:39

i am using this query

我正在使用此查询

select date_time_posting from table where FROM_UNIXTIME(date_time_posting,'%d-%m-%Y')='$c_day_date'

从表中选择date_time_posting FROM_UNIXTIME(date_time_posting,'%d-%m-%Y')='$ c_day_date'

where $c_day_date is having dates in dd-mm-yy format like 25-07-2009

其中$ c_day_date的日期为dd-mm-yy格式,如25-07-2009

My server is in different time zone from mine.Total difference is of about 6 hours i.e. my local timezone is 6 hours ahead of my server timezone.

我的服务器与我的服务器处于不同的时区。总差异大约为6小时,即我的本地时区比我的服务器时区提前6小时。

This query runs in the midnight at around 01:00 according to my timezone but at that time my server remains in the previous day date.

根据我的时区,此查询在午夜大约01:00运行,但那时我的服务器仍然在前一天的日期。

Then at that time this query doesnt give me desired result.Why this problem is persisting when im doing everything with the already stored data.Why this time difference is affecting my query and how can i rectify it????

然后在那个时候这个查询并没有给我想要的结果。为什么这个问题在我用已经存储的数据做所有事情时仍然存在。为什么这个时间差异正在影响我的查询,我怎么能纠正它?

1 个解决方案

#1


You can set per client timezone by sending a query like:

您可以通过发送如下查询来设置每个客户端时区:

$sql = "SET time_zone = timezone;"

check the manual at MySQL to try to rectify this problem.

查看MySQL的手册以尝试纠正此问题。

#1


You can set per client timezone by sending a query like:

您可以通过发送如下查询来设置每个客户端时区:

$sql = "SET time_zone = timezone;"

check the manual at MySQL to try to rectify this problem.

查看MySQL的手册以尝试纠正此问题。