DateTime->Parse
-
Hey Guys, I'm having a little problem parsing a date and time from a string.
DateTime^ start = gcnew DateTime(); temp = ""; this->thisJob->getStartDate(temp); start->Parse(temp);
temp is "5/16/2011" however, after start->parse(temp) the value of start is always "1/1/1 0:0:0" I'm only interested in the date "5/26/2011". MSDN has several differnt "Parse" methods, and I've tried a few others, but the result is always "1/1/1 0:0:0" Sorry for the smileys, I think CP website is taking my returned string I'm typing into the question and converting it into some kind of smiley code.
[Insert Witty Sig Here]
-
Hey Guys, I'm having a little problem parsing a date and time from a string.
DateTime^ start = gcnew DateTime(); temp = ""; this->thisJob->getStartDate(temp); start->Parse(temp);
temp is "5/16/2011" however, after start->parse(temp) the value of start is always "1/1/1 0:0:0" I'm only interested in the date "5/26/2011". MSDN has several differnt "Parse" methods, and I've tried a few others, but the result is always "1/1/1 0:0:0" Sorry for the smileys, I think CP website is taking my returned string I'm typing into the question and converting it into some kind of smiley code.
[Insert Witty Sig Here]
Try something like this...
String ^temp = "5/26/2011"; DateTime start; if (DateTime::TryParse(temp, start)) { // do something with start }
...or this...
String ^temp = "5/26/2011"; try { DateTime start = DateTime::Parse(temp); // do something with start } catch (Exception ^) { }
Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Monday, May 16, 2011 2:32 PM
-
Try something like this...
String ^temp = "5/26/2011"; DateTime start; if (DateTime::TryParse(temp, start)) { // do something with start }
...or this...
String ^temp = "5/26/2011"; try { DateTime start = DateTime::Parse(temp); // do something with start } catch (Exception ^) { }
Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Monday, May 16, 2011 2:32 PM
That works! I'm a bit confused as to why your code works and mine doesn't. What is the difference between SomeDateTimeObject.Parse, and DateTime::Parse?
[Insert Witty Sig Here]
-
That works! I'm a bit confused as to why your code works and mine doesn't. What is the difference between SomeDateTimeObject.Parse, and DateTime::Parse?
[Insert Witty Sig Here]
All the Parse() methods are static (AFAIK) so they return a new DateTime object instead of altering the one you were calling Parse() on. This would have worked;
start = start->Parse(temp);
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
All the Parse() methods are static (AFAIK) so they return a new DateTime object instead of altering the one you were calling Parse() on. This would have worked;
start = start->Parse(temp);
Mark Salsbery Microsoft MVP - Visual C++ :java:
I see, MSDN wasn't too clear on that. It lead me to believe temp would be modified. Thank you, 5's for both.
[Insert Witty Sig Here]