Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to get a first day of a month as week day, e.g. on 01/January/2013 output should be Thursday.
Posted
Updated 20-Mar-13 1:05am
v2

The DateTime class has that built in:
C#
DateTime dt = DateTime.ParseExact("01/January/2013", "dd/MMMM/yyyy", CultureInfo.InvariantCulture);
Console.WriteLine(dt.DayOfWeek);
Will Print "Tuesday" since the 1st Jan this year was a Tuesday (not a Thursday as your question states)
 
Share this answer
 
Comments
Monjurul Habib 20-Mar-13 15:19pm    
5++
30 seconds of Google linked me here

http://msdn.microsoft.com/en-us/library/bb762911.aspx[^]

Using Google before posting here makes a lot of sense, we are not here to be your internet search engine. In future try doing some research before you post.
 
Share this answer
 
Take a look: http://msdn.microsoft.com/de-de/library/system.datetime.dayofweek.aspx[^]

// This example demonstrates the DateTime.DayOfWeek property
using System;

class Sample 
{
    public static void Main() 
    {
// Assume the current culture is en-US.
// Create a DateTime for the first of May, 2003.
    DateTime dt = new DateTime(2003, 5, 1);
    Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}", 
                       dt, dt.DayOfWeek == DayOfWeek.Thursday);
    Console.WriteLine("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek);
    }
}
/*
This example produces the following results:

Is Thursday the day of the week for 5/1/2003?: True
The day of the week for 5/1/2003 is Thursday.
*/
 
Share this answer
 
hi anu,

try this

DateTime dt1 = DateTime.Now;
            DateTime now = dt1;
            DateTime firstDay = new DateTime(now.Year, now.Month, 1);

            Console.Write(firstDay.ToShortDateString() + " Week " + now.DayOfWeek.ToString());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900