Question

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!

Was it helpful?

Solution

I think these will do:

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

or:

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

OTHER TIPS

Solved:

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

Thanks for the help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top