Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i wannna build a program where i type the date, and it returns me the day of that specific date.
how can i do that?
Posted
Comments
Andreas Gieriet 11-Feb-13 18:06pm    
You repeat yourself many times below. Read *carefiully*: DateTime is not DateTimePicker!
DateTime is a convenience class to hold dates and time (but not durartions - for that see the TimeSpan class).
Check out the DateTime class and see the constructors and the provided functions to give the day of the week, etc.
Cheers
Andi

Look at the DateTime.DayOfWeek property.
 
Share this answer
 
Comments
appleduardo 11-Feb-13 14:55pm    
but i cant use datetimepicker methods, how can i code it step by step by taking the given date as refference?

lets say i introduce a date through the datetime picker (feb 11 2013, for instance), and i want to know what day was on nov-23-2002 (which i have to type in 3 different textboxes) by taking the first date as a reference to calculate the second one.
Matt T Heffron 11-Feb-13 17:54pm    
None of the solutions that referred to the DateTime data type mentioned using the DateTimePicker. They are different types. You CAN use DateTime without using DateTimePicker. Create the DateTime value: new DateTime(int year, int month, int day)
Really :
C#
var day = DateTime.Parse("2013/2/11").DayOfWeek; // gives you monday
 
Share this answer
 
Comments
appleduardo 11-Feb-13 14:55pm    
but i cant use datetimepicker methods, how can i code it step by step by taking the given date as refference?

lets say i introduce a date through the datetime picker (feb 11 2013, for instance), and i want to know what day was on nov-23-2002 (which i have to type in 3 different textboxes) by taking the first date as a reference to calculate the second one.
Hi,

Use the DateTime.Parse[^], the DateTime.ParseExact[^], the DateTime.TryParse[^] or the DateTime.TryParseExact[^] method to parse the given date.
Then, you can use the DateTime.Day or the DateTime.DayOfWeek property to get the day of that specific date.
 
Share this answer
 
v3
Comments
appleduardo 11-Feb-13 14:54pm    
but i cant use datetimepicker methods, how can i code it step by step by taking the given date as refference?

lets say i introduce a date through the datetime picker (feb 11 2013, for instance), and i want to know what day was on nov-23-2002 (which i have to type in 3 different textboxes) by taking the first date as a reference to calculate the second one.
Thomas Daniels 12-Feb-13 2:01am    
You can use DateTime without using a DateTimePicker. With Parse, ParseExact, TryParse and TryParseExact, you can parse a string to a DateTime.
Hi
You can use from bellow code for this action:

int m = 11, y = 2002, d = 23;
DateTime time = new DateTime(y, m, d);

Console.WriteLine(time);
Console.WriteLine(time.DayOfWeek);


I hope it's helpful for you.
 
Share this answer
 
Have a look here:
http://msdn.microsoft.com/en-us/library/system.datetime_methods.aspx[^]
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]
http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek%28v=vs.95%29.aspx[^]

[EDIT]

1) Use ValueChanged for event for DateTimePicker:
VB
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        Dim dt As Date

        dt = Me.DateTimePicker1.Value
        Me.Label1.Text = dt.ToString & " is " & Format(dt, "dddd")

    End Sub


or

2) set Format and CustomFormat property for DateTimePicker control
DateTimePicker1.Format = Custom<br />
DateTimePicker1.CustomFormat = "dddd"<br />

DateTimePicker will show you only the name of day.

[/EDIT]
 
Share this answer
 
v2
Comments
appleduardo 11-Feb-13 14:55pm    
but i cant use datetimepicker methods, how can i code it step by step by taking the given date as refference?

lets say i introduce a date through the datetime picker (feb 11 2013, for instance), and i want to know what day was on nov-23-2002 (which i have to type in 3 different textboxes) by taking the first date as a reference to calculate the second one.
Maciej Los 11-Feb-13 15:16pm    
Do i ever wrote you to use DateTime picer methods? No.
See my answer after update.

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