du4822 2015-12-12 15:26
浏览 169

查询任何/所有年份的指定月份和日期的时间戳记录

I have a mySQL table that stores the high temperatures for every day over a span of several years. When A given day's temp is logged to the database, a UNIX timestamp for midnight GMT time for that day is logged as well. I need to run a query that will return all the temps over the years and the date they're associated with for any user-selected day and month. So for example, if the use selects August 11th, I need the high temperature for 8/11/2003, 8/11/2004, 8/11/2005, etc (1060560000, 1092182400, 1123718400, respectively)... all records with a timestamp that will convert to that date.

I know I can generate the exact timestamps for that date for the years the data spans and use them in the query like this:

SELECT tStamp, high_temp FROM temps WHERE tStamp=1060560000 OR tStamp=1092182400 OR tStamp=1123718400;

but this obviously would not be ideal. In order to allow for an unlimited range of years, I'll need something that can find multiples or something to that effect... I think?

I tried (in PHP):

$in = $_POST['date']; // ex: 8/11
$mult = strtotime($in . '/1970 00:00:00');

$sql = "SELECT tStamp, high_temp FROM temps WHERE MOD(tStamp, $mult) = 0";

....

but this did not return any records for August 11th. I'm not sure where to go from here. Any insight would be greatly appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?