duanliao6077 2014-11-23 04:06
浏览 37
已采纳

从mysql表中获取哪些列类型为“timestamp”的数据?

In mysql database I've a date value which data type is timestamp. It's showing this value is something like this : 1415607900, 1394439900, 1412929500 etc.

Now In Html form I can pickup a date. Date value is m/d/y format and this date is for searching data to DB. I can pickup Date From or Date To or Both from this html form field.

Date from is searching data from pickup date to current date.
Date To is searching all data until picktup Date.
If both date value exsit then it's searching data between this 2 dates.

So how do I search data against this timestamp ?

Please check my following mysql query which I'm running but can't get right result. I'm highly appreciate your suggestions/solutions. Thank You.

if(!empty($ad_datefrom) && empty($ad_dateto)){    
    $getSearch .= "AND cd.created_date2 BETWEEN '$ad_datefrom' AND '$date' ";   
}

if(!empty($ad_dateto) && empty($ad_datefrom)){    
    $getSearch .= "AND cd.created_date2 BETWEEN '0000-00-00' AND '$ad_dateto'"; 
}

if(!empty($ad_datefrom) && !empty($ad_dateto)){
    $getSearch .= "AND cd.created_date2 BETWEEN '$ad_datefrom' AND '$ad_dateto' ";  
}

----------------------------------------------------------------------------------
cd = contact_details Table,  
created_date2 = date column (data type : timestamp)  
$date = current date which format is m/d/y

Update :

/* this is for Date from*/
if(!empty($ad_datefrom) && empty($ad_dateto)){    
        $getSearch .= "AND cd.created_date BETWEEN UNIX_TIMESTAMP('$ad_datefrom') AND UNIX_TIMESTAMP('$date') ";    
}

/* this is for Date To*/
if(!empty($ad_dateto) && empty($ad_datefrom)){    
    $getSearch .= "AND cd.created_date BETWEEN UNIX_TIMESTAMP('0000-00-00') AND UNIX_TIMESTAMP('$ad_dateto') "; 
}

/* this is for Date from and Date To*/
if(!empty($ad_datefrom) && !empty($ad_dateto)){
    $getSearch .= "AND cd.created_date BETWEEN UNIX_TIMESTAMP('$ad_datefrom') AND UNIX_TIMESTAMP('$ad_dateto')";    
}
  • 写回答

1条回答 默认 最新

  • duanao6704 2014-11-23 04:14
    关注

    You can use FROM_UNIXTIME() to convert Unix time into date time.

    Here is an example SELECT * FROM tbl where FROM_UNIXTIME(dt) between '2014-10-01 00:00:00' and "2014-11-01 00:00:00'

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭