Good morning
I have an interesting situation:
1 June 2018 = 43252 as Integer 30 May 2018 = 43250 as Integer
I try to convert a date to the first of the respective month (reporting month) with the following code:
DECLARE @InputDate DateTime, @Result Float, @Date DateTime
Set @InputDate = '2018/06/18 23:13:05'
If isDate(@InputDate) = 0
BEGIN
Set @Result = 0
END
ELSE
BEGIN
Set @Date = DATEFROMPARTS(Year(@InputDate), Month(@InputDate), 1)
Set @Result = cast (cast(@Date as datetime) as float)
Select @Date, @Result
END
The result for @Date is '2018-06-01 00:00:00.000' as expected but the result for @Result = 43250 which is 30 May 2018. How does this happen?