Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Change Date format

Change Date format

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcareer
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manju 123
    wrote on last edited by
    #1

    Hi all. I want to change a date format from dd/mm/yyyy to yyyy/mm/dd.. suppose i am getting date as.. Date = 12/04/2008 i want it to be changed to 2008/04/12.. I am trying with the below code but i am getting the system time.. the code is

    CString Date,Datee;
    Date = "12/05/2008;"
    SYSTEMTIME sysTime;
    GetSystemTime(&sysTime);
    Datee.Format("%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);

    can anyone help me manju

    Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju

    C _ enhzflepE S D 5 Replies Last reply
    0
    • M manju 123

      Hi all. I want to change a date format from dd/mm/yyyy to yyyy/mm/dd.. suppose i am getting date as.. Date = 12/04/2008 i want it to be changed to 2008/04/12.. I am trying with the below code but i am getting the system time.. the code is

      CString Date,Datee;
      Date = "12/05/2008;"
      SYSTEMTIME sysTime;
      GetSystemTime(&sysTime);
      Datee.Format("%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);

      can anyone help me manju

      Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      manju#123 wrote:

      I want to change a date format from dd/mm/yyyy to yyyy/mm/dd..

      It would help a lot if you would tell us what this date is: is it stored in a plain string, a COLEDataTime object, ... ? Don't you have the different elements of the data (day, month and year) separately available ?

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • M manju 123

        Hi all. I want to change a date format from dd/mm/yyyy to yyyy/mm/dd.. suppose i am getting date as.. Date = 12/04/2008 i want it to be changed to 2008/04/12.. I am trying with the below code but i am getting the system time.. the code is

        CString Date,Datee;
        Date = "12/05/2008;"
        SYSTEMTIME sysTime;
        GetSystemTime(&sysTime);
        Datee.Format("%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);

        can anyone help me manju

        Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        manju#123 wrote:

        SYSTEMTIME sysTime; GetSystemTime(&sysTime);

        Gets the current system time in UTC

        manju#123 wrote:

        I am trying with the below code but i am getting the system time..

        because you are using the system time and just formatting it before displaying

        manju#123 wrote:

        Datee.Format("%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);

        Do you try to print the Datee string after the string is formatted? It should now be in the format you need.

        Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

        1 Reply Last reply
        0
        • M manju 123

          Hi all. I want to change a date format from dd/mm/yyyy to yyyy/mm/dd.. suppose i am getting date as.. Date = 12/04/2008 i want it to be changed to 2008/04/12.. I am trying with the below code but i am getting the system time.. the code is

          CString Date,Datee;
          Date = "12/05/2008;"
          SYSTEMTIME sysTime;
          GetSystemTime(&sysTime);
          Datee.Format("%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);

          can anyone help me manju

          Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju

          enhzflepE Offline
          enhzflepE Offline
          enhzflep
          wrote on last edited by
          #4

          Try using GetLocalTime...

          1 Reply Last reply
          0
          • M manju 123

            Hi all. I want to change a date format from dd/mm/yyyy to yyyy/mm/dd.. suppose i am getting date as.. Date = 12/04/2008 i want it to be changed to 2008/04/12.. I am trying with the below code but i am getting the system time.. the code is

            CString Date,Datee;
            Date = "12/05/2008;"
            SYSTEMTIME sysTime;
            GetSystemTime(&sysTime);
            Datee.Format("%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);

            can anyone help me manju

            Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju

            S Offline
            S Offline
            Sandeep Saini SRE
            wrote on last edited by
            #5

            If you are talking about Date variable then you can get the desired format using -

            CString Date = "12/05/2008";
            CString YY,MM,DD;
            int nLen;

            nLen = Date.ReverseFind('/');
            YY = Date.Right(nLen - 1);
            Date = Date.Left(nLen);

            nLen = Date.ReverseFind('/');
            MM = Date.Right(nLen);
            Date = Date.Left(nLen);

            DD = Date;
            CString sNewDateFormat;
            sNewDateFormat.Format("%s/%s/%s",YY,MM,DD);

            And if you are talking about the variable Datee, then the code written by you is fine.

            1 Reply Last reply
            0
            • M manju 123

              Hi all. I want to change a date format from dd/mm/yyyy to yyyy/mm/dd.. suppose i am getting date as.. Date = 12/04/2008 i want it to be changed to 2008/04/12.. I am trying with the below code but i am getting the system time.. the code is

              CString Date,Datee;
              Date = "12/05/2008;"
              SYSTEMTIME sysTime;
              GetSystemTime(&sysTime);
              Datee.Format("%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);

              can anyone help me manju

              Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              manju#123 wrote:

              I am trying with the below code but i am getting the system time..

              No surprise there since you are explicitly using sysTime members.

              manju#123 wrote:

              can anyone help me

              Yes. To get your yyyy/mm/dd format, use:

              Datee.Format("%04d/%02d/%02d", sysTime.wYear, sysTime.wMonth, sysTime.wDay);

              Now if you are actually wanting to use the date in the Date variable, try:

              CString Date = "12/05/2008";
              COleDateTime dt;
              dt.ParseDateTime(Date);
              CString Datee = dt.Format("%Y/%m/%d");

              "Love people and use things, not love things and use people." - Unknown

              "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups