I am trying to get the current date in the format of YearMonthDay (2005117) in C++.NET.
I have tried all sorts of ways, but can't get the date on it.
I have tried to take dt.Year and concat dt.Month and dt.Day, but end up with 200511.
I have tried taking the int dt.Day and pass it into an array of string versions of dates.
The command window gives me a good value, but string pointer it is returning to is bad.
The last thing I just tried was
DateTime dt = DateTime::Now;
String* delimStr = S"/";
Char delimiter[] = delimStr->ToCharArray();
String* saDate[] = dt.ToShortDateString()->Split( delimiter );
String* sDate = saDate[2];
sDate = String::Concat( sDate, saDate[0] );
sDate = String::Concat( sDate, saDate[1] );
and that gets me 200511 also.
Any ideas? This doesn't make any sense.
Year and month work fine, but no matter what, I can't get a date...
-
-
brussell wrote:I am trying to get the current date in the format of YearMonthDay (2005117) in C++.NET.
That format is ambiguous, isn't it? You get 2005117 for both 2005-01-17 and 2005-11-07.
EDIT: Oh, and I'm guessing that dt.Day is the day of the week.
EDIT2: No, I'm wrong... never mind.
-
Yeah, I realized that.
Month and date should be double digit always.
I am looking to get 20051107.
That doesn't change the problem I am having with the date.
-
Just realized I was in Release build and wasn't using the variable anywhere yet so it was being optimized away.
I have switched my code to: String* sDate = dt.ToString( "yyyyMMdd" );
Thanks!
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.