How to concatenate variables to form a datetime object in a mysql query

问题: I have a condition where a db table appointment consists of 2 columns viz. date (datatype is date) and hour (datatype is int (0-23)). Those columns represent the date of ap...

问题:

I have a condition where a db table appointment consists of 2 columns viz. date (datatype is date) and hour (datatype is int (0-23)). Those columns represent the date of appointment request(date) and hour of appointment seeked (hour). I need to display every appointment requests which lies ahead of current time. If the date was a datetime object we could do :

Select * from appointment where `date`-current_timestamp()>0

Since I have a date value separate and hour value separate how can I join them to make a datetime value so that something like ``date+hour+":00:00"-current_timestamp()>0 would be valid. I tried this concatenation by + but it didnt work.


回答1:

One method is to combine date and time. Another is to do two comparisons:

select a.*
from appointment a
where a.date > curdate() or
      (a.date = curdate() and a.time > curtime());
  • 发表于 2018-07-13 23:39
  • 阅读 ( 276 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除