mysql 时间戳与日期格式的相互转换

mysql 时间戳与日期格式的相互转换

1、UNIX时间戳转换为日期函数:FROM_UNIXTIME()

  • select FROM_UNIXTIME(1507614043);

输出:2017-10-10 13:40:43

mysql查询当天的记录数:

  • $sql=”select * from 表 Where DATE_FORMAT(FROM_UNIXTIME(列),’%Y-%m-%d’) = DATE_FORMAT(NOW(),’%Y-%m-%d’) order by id desc”; 

2、日期转换为UNIX时间戳函数: UNIX_TIMESTAMP()

  • Select UNIX_TIMESTAMP('2017-10-10 13:40:43');

输出:1507614043 

查看当前时间的时间戳:

  • Select UNIX_TIMESTAMP(NOW());

PHP 时间戳与日期格式的相互转换:

UNIX时间戳转换为日期用函数: date()

  • date('Y-m-d H:i:s', 1507614043); 

日期转换为UNIX时间戳用函数:strtotime()

  • strtotime('2017-10-10 13:40:43');

上一篇: 树莓派Raspberry玩耍过程记录
下一篇: 三种编程命名规则(匈牙利法,小驼峰法,大驼峰法)

发表评论


数据库出错:

MySQL Query Error
Mysql error description: Duplicate entry '0' for key 'uid'
Mysql error number: 1062
Date: 2024-06-03 @ 20:07
Script: http://blog.is36.com/index.php/module/action/param1/tagslist/page/3/user/%E6%AD%A3%E5%86%B0/wap/archives/488/archives/463/comments/archives/488/category/technology_all/links/archives/487/date/202302/archives/https:/blog.is36.com/index.php/module/action/param1/tagslist/page/3/user/%E6%AD%A3%E5%86%B0/wap/archives/488/archives/463/comments/archives/488/category/technology_all/links/archives/487/date/202302/archives/page/5/?action=show&id=452