Home > 网站建设 > mysql 从datetime类型中取日期

mysql 从datetime类型中取日期

在mysql中,我要取出当天录入的记录。里面录入时间: AddTime是datetime类型,假设其值为:2007-08-06 10:12:22

select * from table1 where AddTime='2007-08-06'

这里的时间AddTime要通过什么函数处理才能得到日期部分,从而可以和后面的日期能够比较。

取当天:
select * from table1 where TO_DAYS(AddTime)=TO_DAYS(NOW());

这样也可以:SELECT * from taffair where date_format(TAffairDate,'%Y-%m-%d')='2007-04-04';

问题是这样的,我的表中有一个字段类型为datetime,默认存储格式:
0000-00-00 00:00:00

我通过MYSQL的C API取到值,存到一个char型数组。内容与前面类似。我现在想用取到的这个时间与当前系统时间作比较,但不知道怎么把这个数组的内容转换为到1970年之间的秒数啊?就是达到C中time函数的效果。

unix_timestamp()

Categories: 网站建设 Tags:
  1. No comments yet.
  1. No trackbacks yet.

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).