有两个途径可获得
1、利用TO_DAYS函数
select to_days(now()) - to_days('20130330')
2、利用DATEDIFF函数
select datediff(now(),'
20130330')
3.
TIMESTAMPDIFF
返回日期或日期时间表达式datetime_expr1 和datetime_expr2the 之间的整数差。其结果的单位由interval 参数给出。interval 的法定值同TIMESTAMPADD()函数说明中所列出的相同,可以使用:FRAC_SECOND、SECOND、 MINUTE、 HOUR、 DAY、 WEEK、 MONTH、 QUARTER或 YEAR。
如:
SELECT TIMESTAMPDIFF(HOUR,’2013-04-12′,NOW());
其中TIMESTAMPDIFF函数最好,可以求两日期之间相隔的月份、
天数、小时、分钟数目等等。很好用!
下面的 程序可以求出linux下当前时间的小时和分钟数
#include <time.h>
#include <stdio.h>
int main()
{
time_t now;
int hour = 0,minute = 0;
now = time(0);
struct tm *tnow = localtime(&now);
printf("%d %d %d %d %d %d\n", 1900+tnow->tm_year,
tnow->tm_mon+1,
tnow->tm_mday,
tnow->tm_hour,
tnow->tm_min,
tnow->tm_sec);
hour = tnow->tm_hour;
minute = tnow->tm_min;
printf("hour is :%d\n",hour);
printf("hour is :%d\n",minute);
}
#include <stdio.h>
int main()
{
time_t now;
int hour = 0,minute = 0;
now = time(0);
struct tm *tnow = localtime(&now);
printf("%d %d %d %d %d %d\n", 1900+tnow->tm_year,
tnow->tm_mon+1,
tnow->tm_mday,
tnow->tm_hour,
tnow->tm_min,
tnow->tm_sec);
hour = tnow->tm_hour;
minute = tnow->tm_min;
printf("hour is :%d\n",hour);
printf("hour is :%d\n",minute);
}