mysql>select now()
+---------------------+
| now() |
+---------------------+
| 2010-08-25 09:34:41 |
+---------------------+
1 row in set (0.00 sec)
mysql>select date_add(now(),interval -1 year)
+----------------------------------+
| date_add(now(),interval -1 year) |
+----------------------------------+
| 2009-08-25 09:34:44 |
+----------------------------------+
1 row in set (0.00 sec)
mysql>select date_sub(now(),interval 1 year)
+---------------------------------+
| date_sub(now(),interval 1 year) |
+---------------------------------+
| 2009-08-25 09:34:46 |
+---------------------------------+
1 row in set (0.00 sec)
mysql>
如果是获取当前时间的话使用mysql自带的函数
curdate()返回日期型数据
'yyyy-mm-dd'
now()返回日期时间型数据
'yyyy-mm-dd
hh:mm:ss'
$sql="insert
into
xxx_table
(xxx_date
,
xxx_datetime)
values(
curdate(),now()
)"
select subdate(curdate(),date_format(curdate(),'%w')-1)//获取当前日期在本周的周一select subdate(curdate(),date_format(curdate(),'%w')-7)//获取当前日期在本周的周日
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)