简体   繁体   English

两个时期之间的MYSQL查询有问题吗?

[英]Trouble with MYSQL query BETWEEN two epoch timestamps?

I have epoch timestamps in my mysql database, I am using a Jquery datepicker to choose BETWEEN two dates. 我的mysql数据库中有新纪元时间戳,我正在使用Jquery datepicker选择两个日期之间。 It works great when I choose at minimum between 1 day, but if I choose Sunday - Sunday ( the same day ) it should bring back records that have fallen on that day. 当我至少选择1天之间的时间时,效果很好,但是如果选择周日-周日(同一天),它应该带回当天的记录。

I am assuming it is because of the epoch timestamp integrated withing the datepicker.. When you choose a date, like today, it comes back with : 我假设这是由于与日期选择器集成的纪元时间戳。当您选择一个日期(如今天)时,它会返回:

BETWEEN 1317103200 AND 1317103200 ....

I know how epoch timestamps work and it seems like it is to the second when you convert and do the math... How do I implement a DISTINT value for that FULL DAY -- so it just looks at the full 24 hours and not down to the millisecond??? 我知道时代的时间戳是如何工作的,当您转换并进行数学运算时,它似乎是秒。...如何为该整天实现DISTINT值-因此它只看整整24小时而不是减少到毫秒???

SELECT category, id, date, title 
FROM myTable
WHERE date BETWEEN $beginDate AND $endDate AND...

Thanks so much!! 非常感谢!!

Use the mktime() function where $month , $day and $year have been populated with the month, day and year from your date text box: 使用mktime()函数,其中$month$day$year已用日期文本框中的月,日和年填充:

// Assumes date is in this format: dd/mm/yyyy, and your $_GET key is 'date'
list($day, $month, $year) = explode('/', $_GET['date']);

$beginDate = mktime(0, 0, 0, $month, $day, $year);
$endDate = mktime(23, 59, 59, $month, $day, $year);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM