I only want to change the MonthlyCalender Month to a variable(May) but for some reason i have to enter the full date which breaks my code, as i search for the month in the variable and then match it so it then excutes the code when it finds the string, below is the code;
Code
if (textDueDate.Contains("May"))
{
DateTime dt = new DateTime();
clndDueDate.SetDate(dt.AddMonths(05));
clndDueDate.Update();
MessageBox.Show("Inside May");
}
else
{
}
This does nothing, So do i use SetDate property in a different way... since i added the month on the Monthly calender.
MessageBox is just my debugger :P
Maybe substring?
Java
DateTimedt=newDateTime(2001, 01, 01); //Works with full dateDateTimedt=newDateTime(null, 01, null); //Not working ;(
Thanks for reading
6 Answers
Know the answer? Post it. Somebody with the same question will find it here.
I prefer not going with string in the month. If culture varies, then your code wont work. U better go with Month Property. As you said, u always want to use month, just ignore rest. There is no constructor in DateTime which takes nullable values, which is not meaning ful way.
Otherwise create your own month enum .
Hi
I m agree with you krishna, so John could refactor his code by introducting an enumeration
enum Months{Jun,Feb,Mar,.........}; to avoid hard coding with strings
Bechir BejaouiRank #144 · 15.9K pointsPosted Sep 9, 2010, 3:47 PM EDT
John Smith5 pointsPosted Sep 9, 2010, 4:04 PM EDT
Bechir BejaouiRank #144 · 15.9K pointsPosted Sep 11, 2010, 6:07 AM EDT
I have a question why in May if section the code is different?
John Smith5 pointsPosted Sep 11, 2010, 9:55 AM EDT
Since MonthlyCalender doesn't accept month only for some reason from the DateTime, maybe i should try DateTimePicker.
krishna v30 pointsPosted Sep 11, 2010, 5:27 PM EDT
Otherwise create your own month enum .
Bechir BejaouiRank #144 · 15.9K pointsPosted Sep 12, 2010, 4:40 AM EDT
I m agree with you krishna, so John could refactor his code by introducting an enumeration
enum Months{Jun,Feb,Mar,.........}; to avoid hard coding with strings