Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# C#4.0
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 11-Feb-13 8:24am
Comments
Andreas Gieriet at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Look at the DateTime.DayOfWeek property.
  Permalink  
Comments
appleduardo at 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 at 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)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Really :
var day = DateTime.Parse("2013/2/11").DayOfWeek; // gives you monday
  Permalink  
Comments
appleduardo at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
v3
Comments
appleduardo at 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.
ProgramFOX at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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:
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
DateTimePicker1.CustomFormat = "dddd"

DateTimePicker will show you only the name of day.
 
[/EDIT]
  Permalink  
v2
Comments
appleduardo at 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 at 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)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 85
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100