No sweet without sweat

[C#] - 90일 이내의 날짜를 체크하고 반환하는 조건문 본문

카테고리 없음

[C#] - 90일 이내의 날짜를 체크하고 반환하는 조건문

Remi 2023. 11. 19. 17:21
728x90
반응형
using System;

public class DateChecker
{
    public static void Main()
    {
        // 예제: 현재 날짜를 기준으로 90일 이내의 날짜 체크
        DateTime currentDate = DateTime.Now;
        DateTime targetDate =  /* 여기에 비교할 날짜 입력 */;

        if (IsWithin90Days(currentDate, targetDate))
        {
            // 90일 이내의 경우 처리할 내용
            Console.WriteLine("90일 이내입니다.");
            return;
        }

        // 90일 이상인 경우 처리할 내용
        Console.WriteLine("90일 이상입니다.");
    }

    public static bool IsWithin90Days(DateTime currentDate, DateTime targetDate)
    {
        TimeSpan difference = currentDate - targetDate;
        int daysDifference = difference.Days;

        return daysDifference <= 90;
    }
}
728x90
반응형
Comments