How to display the day of the week in C#

3 Answers

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                DateTime dt = DateTime.Now;

                Console.WriteLine(dt.ToString("ddd")); // Wed
                Console.WriteLine(dt.ToString("dddd")); // Wednesday
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
 
Wed
Wednesday

*/


answered Mar 25, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                DateTime dt = DateTime.Now;

                for (int i = 0; i < 7; i++)
                {
                    Console.WriteLine(dt.ToString("ddd")); 
                    dt = dt.AddDays(1);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
 
Wed
Thu
Fri
Sat
Sun
Mon
Tue

*/


answered Mar 25, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                DateTime dt = DateTime.Now;

                for (int i = 0; i < 7; i++)
                {
                    Console.WriteLine(dt.ToString("dddd")); 
                    dt = dt.AddDays(1);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
 
Wednesday
Thursday
Friday
Saturday
Sunday
Monday
Tuesday

*/


answered Mar 25, 2015 by avibootz

Related questions

1 answer 343 views
1 answer 306 views
1 answer 178 views
3 answers 231 views
1 answer 135 views
1 answer 135 views
...