dph58509 2012-04-03 13:47
浏览 100

按月unix时间戳问题

When i pull a monthly report it's only showing entries from the 2nd day of the month up to the day be before the last of the month. For example a report for month of April only shows:

04/02/12 - 04/29/12

What can i modify to show entries:

04/01/12 - 04/30/12

$month = $_GET['month'];
if ($services =     $db->get_results("SELECT * from vw_newservices where month(from_unixtime(datetime)) = '$month'")) {
foreach ($services as $service) {
$datetime = date("m/d/y",$service->datetime);

Thanks

  • 写回答

1条回答 默认 最新

  • douzhiling3166 2012-04-03 15:35
    关注

    From the manual:

    Note: If you use UNIX_TIMESTAMP() and FROM_UNIXTIME() to convert between TIMESTAMP values and Unix timestamp values, the conversion is lossy because the mapping is not one-to-one in both directions. For example, due to conventions for local time zone changes, it is possible for two UNIX_TIMESTAMP() to map two TIMESTAMP values to the same Unix timestamp value. FROM_UNIXTIME() will map that value back to only one of the original TIMESTAMP values.

    See here.

    If you want to have unix_timestamps without consideration of time zones, you can calculate it yourself.

    In MySQL:

    From timestamp to unixtime:

    SELECT timestampdiff(second, '1970-01-01', yourTimestampColumnOrValue);
    

    The other way

    SELECT timestampadd(second, yourTimestampColumnOrValue, '1970-01-01');
    

    For SQL Server see this link.

    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用