© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3d ago•
12 replies
Kiel

Help with a logic problem with `DateOnly`?

beginner
I need a little bit of logic help with something I'm writing for work.

I wrote this little snippet on lab.razor.fyi to test it. The last ⁨⁨⁨⁨
Test()
Test()
⁩⁩⁩⁩ invocation does not behave as expected and I'm not sure what I need to change about it. I want the loan amount to be the amount for the current "year" of the loan, which varies based on the current date and the month the loan started on. The first three work as expected, but I have one loan that starts in the middle of the year and for some reason when it picks up from $0 it immediately starts using 2023 numbers instead of 2022 numbers.

- a loan that started on 12/2018 should use 2022's numbers from 12/2021 to 11/2022, 2023's numbers from 12/2022 to 11/2023, etc...
- a loan that started on 01/2022 should use 2022's numbers from 01/2022 to 12/2022, 2023's numbers from 01/2023 to 12/2023, etc...
- a loan that started on 03/2021 should use 2022's numbers from 03/2021 to 02/2022, 2023's numbers from 03/2022 to 02/2023, etc...
- a loan that started on 08/2022 should be $0 from 01/2022 to 07/2022, use 2022's numbers from 08/2022 to 07/2023, etc... (this is what's failing, it's using 2023's numbers from 08/2022 onwards)

I know I need to edit the formula for ⁨⁨⁨⁨⁨⁨⁨
selectedYear
selectedYear
⁩⁩⁩⁩⁩⁩⁩ but I don't know what or how I need to change
⁨⁨⁨⁨⁨⁨⁨
var selectedYear = currentDate < loanDate
    ? 0
    : currentDate > endDate
        ? endDate.Year + 1
        : endDate.Year;
var selectedYear = currentDate < loanDate
    ? 0
    : currentDate > endDate
        ? endDate.Year + 1
        : endDate.Year;
⁩⁩⁩⁩⁩⁩⁩
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Help with program logic
C#CC# / help
3y ago
Business Logic Problem
C#CC# / help
14mo ago
✅ DateOnly.TryParse Vs DateOnly.TryParseExact use cases
C#CC# / help
11mo ago
Need help with GIT logic
C#CC# / help
2y ago