Friday, January 27, 2023

t+2 days in c#

using System;

class Program
{
    static void Main(string[] args)
    {
        DateTime currentDate = DateTime.Now;
        DateTime tPlus2Date = currentDate.AddDays(2);

        // Check if the date is a weekend day
        while (tPlus2Date.DayOfWeek == DayOfWeek.Saturday || tPlus2Date.DayOfWeek == DayOfWeek.Sunday)
        {
            // If it is a weekend day, add another day
            tPlus2Date = tPlus2Date.AddDays(1);
        }

        Console.WriteLine("T+2 date without weekend: " + tPlus2Date.ToString("dd-MM-yyyy"));
    }
}



using System;

class DateFetcher
{
    static void Main(string[] args)
    {
        DateTime currentDate = DateTime.Now;

        DateTime tPlusTwoDate = currentDate;
        int counter = 0;

        while (counter < 2)
        {
            tPlusTwoDate = tPlusTwoDate.AddDays(1);
            if (tPlusTwoDate.DayOfWeek != DayOfWeek.Saturday && tPlusTwoDate.DayOfWeek != DayOfWeek.Sunday)
            {
                counter++;
            }
        }

        Console.WriteLine("T+2 date (excluding weekends): " + tPlusTwoDate.ToString("MMM dd yyyy"));
    }
}

No comments:

Post a Comment