本季度的第一天 ,然後你可以把字符串再轉換為日期。 方法很多,包括同一個函數的別名(同義詞)也很多。比如CURDATE(),CURRENT_DATE(), CURRENT_DATE, NOW 等都可以返回當天
mysql教程> select CURDATE(),ELT(QUARTER(CURDATE()),
-> year(CURDATE())*1000+0101,
-> year(CURDATE())*1000+0401,
-> year(CURDATE())*1000+0701,
-> year(CURDATE())*1000+1001) as firstDayofQ;
+------------+-------------+
| CURDATE() | firstDayofQ |
+------------+-------------+
| 2009-05-19 | 2009401 |
+------------+-------------+
1 row in set (0.00 sec)
mysql>
用mysql語句獲取本季度的第一天
本月的第一天,
date(
concat(year(curdate()),'-',month(curdate()),'-','1'))
本周的第一天
curdate()-
WEEKDAY(curdate())
用mysql語句獲取本季度的第一天
date(
concat(year(curdate()),'-',
if(quarter(curdate())=1,1,if(quarter(curdate())=2,4,if(quarter(curdate())=3,7,10))
用mysql語句獲取本季度的第一天:
優化:
date(
concat(year(curdate()),'-',elt(quarter(curdate()),1,4,7,10),'-',1))
本周的第一天
date_add(date('2009-5-29'),INTERVAL -weekday('2009-5-29') day)
mysql 獲取當天發布文件內容sql語句
SELECT * FROM `p8_memberdata` where regdate BETWEEN (UNIX_TIMESTAMP(NOW())-86440) AND NOW()
SELECT * FROM `p8_memberdata` WHERE DATE_FORMAT(FROM_UNIXTIME(regdate),'%Y-%m-%d')= DATE_FORMAT(NOW(),'%Y-%m-%d') order by uid desc