LAST_DAY( ),CURDATE(),WEEKDAY(),DATE_SUB(),MONTH(),DAY()
SELECT
DATE_FORMAT(CURDATE() ,'%Y/%m/01') , #月初LAST_DAY(CURDATE()) #月底
※※※※※※※※※※求年初第一個禮拜一※※※※※※※※※※※
SELECT
IF(DAYOFWEEK(getDate.firstDate) =2,
getDate.firstDate,
DATE_ADD(getDate.firstDate, INTERVAL 7-WEEKDAY(getDate.firstDate) DAY)
) AS firstMonday
FROM
(SELECT
DATE_SUB(
DATE_SUB(
mydate.todate,
INTERVAL MONTH(mydate.todate)-1 MONTH),
INTERVAL DAY(mydate.todate)-1 DAY
) AS firstDate
FROM
(SELECT IFNULL(?, CURDATE()) AS todate) AS mydate
)AS getDate
[MYSQL ]求月初及求月底,使用DAYOFWEEK( ) , DATE_ADD () , LAST_DAY( ), CURDATE () , WEEKDAY( ) , DATE_SUB () , MONTH() , DAY( )
其它文章
沒有留言:
張貼留言