dtest84004 2013-04-26 18:13
浏览 38
已采纳

选择与时间戳相同的日期

I would like to fetch one or several rows from the databases (depedning on results) for a flight ID and a given date. However, I do not know how I can do that. I got the flightId (called flight in table) and I got a unixtimestamp for the date of the flight.

What should my query look like?

This is my table:

CREATE TABLE IF NOT EXISTS `flight` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `foreign_id` int(11) DEFAULT NULL,
  `flight` varchar(45) DEFAULT NULL,
  `origin` varchar(100) DEFAULT NULL,
  `notes` mediumtext,
  `date_original` datetime DEFAULT NULL,
  `date_current` datetime DEFAULT NULL,
  `type` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;

Edit
I have tried several queries, but since I only have the timestamp I can't seem to figure out how to get it from a timestamp to a datetime concerning only the date in question. The timestamp gives an exact second of the day, however, I need to search the whole day (e.g. 2013-04-26 00:00:00 to 2013-04-26 23:59:59)... So basically, I can't get futher than...

SELECT date_original, notes FROM flight WHERE flight = '{$a_sFlightId}' AND date_original ...?
  • 写回答

1条回答 默认 最新

  • donglu1973 2013-04-26 18:18
    关注
    SELECT ...
    WHERE date(from_unixtime($your_unix_timestamp)) = date(date_original)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)