I have a requirement for a date column.
Condition: If the date column value is any date other then the 1st of its month then the same has to be replaced to 1st of that month, say for example today its 05-01-2017 and it has to be replaced by 01-01-2017. Similarly for 15th of the month.
I have achieved the same using below query:
select 'date column',
case when datediff(DAY,-15, 'date column') != 41043 then
DATEADD(dd,-(DAY( 'date column')-1), 'date column')
end
from TABLE
This I cracked by running below query:
select datediff(DAY,-15,'date column')
from TABLE
This gives value "41043", which I used in my query.
But I have two concerns here
- what is this value "41043" ?? like is it ASCII value of that date or subtraction of date from SQL beginning date ..etc..
- Is there any other Simpler way to achieve my query?
Please suggest.