doulang6013 2012-06-22 13:48
浏览 158
已采纳

如何获取特定日期的所有时间戳? PHP

I have rows in a MySQL database, and each has a timestamp value. (ie 1340296188)

I am trying to find all entries for the last 7 days. I know how to do a query to find all WITHIN the last 7 days, something like:

$lastweek = time() - 604800;
$results = mysql_query("SELECT * FROM table WHERE timestamp > $lastweek");

However, I need to be able to get each day seperately. How would I do this query? I don't know how to find from the above results which ones are for which specific date.

  • 写回答

2条回答 默认 最新

  • douxunwei8259 2012-06-22 13:54
    关注

    You're pretty much there already; you just need to parse the timestamp field in $results.

    A day is (60 * 60 * 24) seconds, so you can divide each row's timestamp field by 86400, turn it into an integer, and the result is the number of days ago that this entry occurred.

    For each row in your dataset:

    $daysAgo = int($row["timestamp"] / 86400);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码