dsplos5731 2014-01-22 01:02
浏览 40

如何使用Mysql时间戳创建日期范围查询?

just need a little help here I hope you can help me with my simple problem.

I have a table that consist of shops data. In my PHP page the user can register their shops. And in registration the day that the user registered his/her account will be save in the database table and will format as a TIMESTAMP.

I have no problem with that. In my backend page there is a form for advance searching method. In my form, there is a dropdown field and beside it there is a datepicker that will format as mm/dd/yyyy so I have a 2 datepicker for that which is from and to.

My problem is:

I formatted the datepicker result using the strtotime() function in PHP. And I have a query like this.

$query = "SELECT * FROM shops
          WHERE status = '".$status."'
          AND registered BETWEEN ('".$from." AND ".$to."')";

Sample output of query is:

 SELECT * FROM shops WHERE status = 'P' AND registered BETWEEN ('1388505600' AND '1391097600');

Now I have a timestamp result for $from and $to. How can I filter it in mysql?

Ok that's all. Thanks in advance.

  • 写回答

4条回答 默认 最新

  • dskld5423 2014-01-22 01:08
    关注

    You need to remove the quotes around the timestamps and you need to use FROM_UNIXTIME() if the column registered is not in UNIX time already.

    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题