79824114

Date: 2025-11-19 06:21:15
Score: 0.5
Natty:
Report link
declare @from datetime = '2025-08-16', @to datetime='2025-11-15'
select DATEDIFF(month, @from, @to) - case when DATEPART(day, @from) > DATEPART(day, @to) then 1 else 0 end as months

This calculates months elapsed between two dates from date to date. Subtracts 1 if the day part of @from is greater than that of @to.

These are the results:

@from = '2025-01-27', @to='2025-02-28' => 1

@from = '2025-01-28', @to='2025-02-28' => 1

@from = '2025-01-29', @to='2025-02-28' => 0

@from = '2025-01-30', @to='2025-02-28' => 0

@from = '2025-01-31', @to='2025-02-28' => 0

@from = '2025-01-31', @to='2025-03-01' => 1

@from = '2025-08-16', @to='2025-09-15' => 0

@from = '2025-08-16', @to='2025-09-16' => 1

@from = '2025-08-16', @to='2025-11-15' => 2

@from = '2025-08-16', @to='2025-11-16' => 3

@from = '2025-08-16', @to='2025-11-30' => 4

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • User mentioned (0): @from
  • Low reputation (0.5):
Posted by: Polymath