1

I have events stored in the MySQL datebase with start date and time stored in column 'startTimeStamp' in UNIX format.

When I try to get events for particular date using simple query

SELECT * FROM events WHERE FROM_UNIXTIME(startTimeStamp, '%Y-%m-%d') = '2013-08-20'

everything works fine when date and time under timestamp is bigger then 2AM (i.e. 2013-08-20 03:00:00) but when it's earlier it's not displaying in same day.

Quick example: I have two events - same date but different time

  1. 2013-08-20 03:00:00 (1376960400)
  2. 2013-08-20 00:00:00 (1376949600)

I will get the first one when I run query mentioned before, but not the second one. To get the second one I have to query for events from day earlier (2013-08-19)

Do you have any idea why? Maybe I'm missing something?

Thanks a lot!

4

4 回答 4

0

看看你的时区是什么:

SELECT @@global.time_zone, @@session.time_zone;

然后正确设置:

SET time_zone = timezonename;

编辑:这可能会有所帮助:MySQL 日期时间字段和夏令时——我如何引用“额外”小时?

于 2013-08-19T11:33:19.387 回答
0

这基本上是因为 Unix 时间戳的含义。这只是从 1-1-1970 的秒数,所以从技术上讲,1376949600 的值可能仍然是前一天,这取决于您的时区。

就我而言:

echo date("d-m-Y h:i", 1376949600);
// output: 19-08-2013 11:00
于 2013-08-19T11:37:28.330 回答
0

我想你可能选择了一个夏令时适用的地方。在这种情况下,时间转移主要是在凌晨 2 点到 3 点之间完成,这可能会导致不同的日子。

于 2013-08-19T11:34:27.293 回答
0

像这样使用:

$d="1376960400";
echo date("Y-m-d",$d);

您可以从此链接使用您想要的格式

于 2013-08-19T12:03:34.503 回答