Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

DateTime.Day problem in C++.NET

Back to Forum: Tech Off
  • User profile image
    brussell

    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...

  • User profile image
    Maurits

    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.

  • User profile image
    brussell

    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.

  • User profile image
    brussell

    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!

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.