[Solved] How can I find the day of the year, year, month and day for now in C#? [duplicate]


To get the numbers with 0 padded on left, you will have to use string format.

        int doy = DateTime.Now.DayOfYear;// Day of the year
        string yr = DateTime.Now.ToString("yy");// Two digit year
        string mon = DateTime.Now.Month.ToString("d2"); // Two digit month (zero on left for small numbers)
        string day = DateTime.Now.Day.ToString("d2"); // Two digit day   (zero on left for small numbers)
    Console.WriteLine(doy);
    Console.WriteLine(yr);
    Console.WriteLine(mon);
    Console.WriteLine(day);

solved How can I find the day of the year, year, month and day for now in C#? [duplicate]