Answered by:
The best overloaded method match for DateTime...

Question
-
Quick question guys, need to compare two dates to which one is earlier. One of these is the current DateTime, which is okay. The other one uses fields from a database.
String currentdateandtime = DateTime.Now.ToString("yyyyMMddhhmm"); DateTime taskdateandtime = new DateTime(schedStringSplit[4], schedStringSplit[3], schedStringSplit[2], schedStringSplit[0], schedStringSplit[1], 0);
I get 'The best overloaded method match for 'System.DateTime.DateTime(int, int, int, int, int, int) has some invalid arguments'. Why is this?
Thanks
Answers
-
What does the variable schedStringSplit contrains? Is it of type integer?
If not integer type then use either
int.Parse(schedStringSplit[4])
or
int temp1;
int.TryParse(schedStringSplit[4], out temp1);
Do the same for the remaining.
Thanks,
A.m.a.L
[MVP Visual C#]
Dot Net Goodies
Don't hate the hacker, hate the code - Proposed as answer by Mike Dos Zhang Thursday, September 30, 2010 10:53 AM
- Marked as answer by Mike Dos Zhang Wednesday, October 6, 2010 3:25 AM
-
Hi chris7197,
Welcome to MSDN Forums!
Excuse me. Why do you convert the current time to string format value?
The DateTime.Now property will return a DateTime type value, and you can use this value to do the remaining work.
If there’s anything unclear, please feel free to let me know.
Have a nice day!
Mike
-------------------------------------------------------------------
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.
*****************************************************
Sample world! You will get more from this world!
Welcome to the new world!
- Proposed as answer by Mike Dos Zhang Thursday, September 30, 2010 10:52 AM
- Marked as answer by Mike Dos Zhang Wednesday, October 6, 2010 3:25 AM
All replies
-
What does the variable schedStringSplit contrains? Is it of type integer?
If not integer type then use either
int.Parse(schedStringSplit[4])
or
int temp1;
int.TryParse(schedStringSplit[4], out temp1);
Do the same for the remaining.
Thanks,
A.m.a.L
[MVP Visual C#]
Dot Net Goodies
Don't hate the hacker, hate the code - Proposed as answer by Mike Dos Zhang Thursday, September 30, 2010 10:53 AM
- Marked as answer by Mike Dos Zhang Wednesday, October 6, 2010 3:25 AM
-
you need to check while constructing the datetime, that is follows this order:
DateTime date = new DateTime(year, month, Day, hour, min, sec);
and also you need to check hours format (12H or 24H), month and day are matching....
so the best way is to use DateTime.TryParse : this will give a safe date parsing from your string
then you can compare the 2 dates simply date1 > date2
-
Thanks all, it wasn't an int - once it was converted it worked great :)
I do have an issue now. The current datetime is a String , and it won't let me change it to DateTime as it says 'Non invocable member System.DateTime.Now cannot be used like a method'
-
Post the code you are trying with.
Thanks,
A.m.a.L
[MVP Visual C#]
Dot Net Goodies
Don't hate the hacker, hate the code -
Hi chris7197,
Welcome to MSDN Forums!
Excuse me. Why do you convert the current time to string format value?
The DateTime.Now property will return a DateTime type value, and you can use this value to do the remaining work.
If there’s anything unclear, please feel free to let me know.
Have a nice day!
Mike
-------------------------------------------------------------------
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.
*****************************************************
Sample world! You will get more from this world!
Welcome to the new world!
- Proposed as answer by Mike Dos Zhang Thursday, September 30, 2010 10:52 AM
- Marked as answer by Mike Dos Zhang Wednesday, October 6, 2010 3:25 AM
-
Hi chris7197,
Now, I close this thread with mark the reply. We have not seen your response so we cannot know if your issue has been solved by this reply. But I think the reply is helpful on this topic, and it can also help the other communities to solve their issue when they see this thread. Hope you can see this. And thanks for your understanding.
But, please feel free to contact us if you have any response on this question.
Have a nice day!
Mike
*****************************************************
Sample world! You will get more from this world!
Welcome to the new world!