문제

This may seem like a trivial question but I have been working on this for two hours. Basically I need to get the start of the year, i.e. 01/01/2013 from 09/25/2013 by manipulation of the current date.

I have been able to get the beginning of the month but I can't figure out how to get the beginning of the year.

My Code:

SET :testDate = curdate() - DAYOFMONTH(curDAate()) + 1

This got me the first day of the month but I do not know how to do the same thing but allow it so subtract months instead of days.

Any input would be appreciated.

Thanks!

도움이 되었습니까?

해결책

I think these will do:

    = CURDATE() - DAYOFYEAR(CURDATE()) + 1

or:

    = CONVERT( CONCAT( YEAR(CURDATE(), '-01-01' ), SQL_DATE )

다른 팁

Solved:

set :test = DATEADD(month, -month(curdate())+1, curdate()) - DAYOFMONTH(curDate()) +1

Thanks for the help!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top