changing the date format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • n78298
    New Member
    • Sep 2006
    • 4

    changing the date format

    Hello Friends

    This is my first post.

    I am having problems in convetring teh date format.
    I have following code.

    if(!strcmp(elem entbuf, "depDate"))
    {
    strncpy((char *)amflightdets[numflights].flightDate, contents, 6);
    amflightdets[numflights].flightDate[6] = '\0';
    }
    I get the value as 180906. (ddmmyy)

    I want to change this value to 18SEP (ddMON) . I want to change this in amflightdets[numflights].flightDate varibale .

    What are the options I can use .

    Thanks in advance..
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    use the second 2 figits of the original value and convert them to a binary number (i.e. month number) use that to look up in and array of month names and add the relevent month name to the firs 2 digits to give ddMON.

    Comment

    • n78298
      New Member
      • Sep 2006
      • 4

      #3
      Thanks for yor reply. I have also tried to code the same thing. extracting the middle 2 digits and using switch case give MON name according to month value.

      But the problem is I m not able to code this as i m new in c++. I m getting errors while trying to do so. If someone can help me with syntax to achieve this ( extracting middle 2 chars and based on that give Month name) I will be very greatful . I searched web for this but of no avail.

      Comment

      • n78298
        New Member
        • Sep 2006
        • 4

        #4
        I need urgent help in this. Any reply will be highly appreciated.

        Comment

        • n78298
          New Member
          • Sep 2006
          • 4

          #5
          Still waiting for some reply. Kindly help

          Comment

          • Rakesh Mutharaju
            New Member
            • Sep 2006
            • 14

            #6
            can u post ur complete code..if the below is not what u want..

            if the input date is 180906 integer.


            unsigned date = 180906;
            char Date_in_DDMONYY[8];
            int date_month = date / 100;
            int month = date_month % 100;
            int date = date_month /100;
            int Digit_in_day = date /10;
            int year = date%1000;
            switch(Digit_in _day)
            {
            case 0:
            Date_in_DDMONYY[0] = L "0";
            break;
            case 1:
            Date_in_DDMONYY[0] = L"1";
            break;
            case 2:
            Date_in_DDMONYY[0] = L"2";
            break;
            case 3:
            Date_in_DDMONYY[0] = L"3";
            break;
            }

            switch(Digit_in _day%10)
            {
            case 0:
            Date_in_DDMONYY[1] = L "0";
            break;
            case 1:
            Date_in_DDMONYY[1] = L"1";
            break;
            case 2:
            Date_in_DDMONYY[1] = L"2";
            break;
            case 3:
            Date_in_DDMONYY[1] = L"3";
            break;

            case 4:
            Date_in_DDMONYY[1] = L"4";
            break;
            case 5:
            Date_in_DDMONYY[1] = L"5";
            break;
            case 6:
            Date_in_DDMONYY[1] = L"6";
            break;
            case 7:
            Date_in_DDMONYY[1] = L"7";
            break;
            case 8:
            Date_in_DDMONYY[1] = L"8";
            break;
            case 9:
            Date_in_DDMONYY[1] = L"9";
            break;

            }

            switch(month)
            {
            case 1:
            Date_in_DDMONYY[2] = L" J";
            Date_in_DDMONYY[3] = L"A";
            Date_in_DDMONYY[4] = L"N";
            break;

            case 2:
            Date_in_DDMONYY[2] = L" F";
            Date_in_DDMONYY[3] = L"E";
            Date_in_DDMONYY[4] = L"B";
            break;
            case 3:
            Date_in_DDMONYY[2] = L" M";
            Date_in_DDMONYY[3] = L"A";
            Date_in_DDMONYY[4] = L"R";
            break;
            case 4:
            Date_in_DDMONYY[2] = L" A";
            Date_in_DDMONYY[3] = L"P";
            Date_in_DDMONYY[4] = L"R";
            break;
            case 5:
            Date_in_DDMONYY[2] = L" M";
            Date_in_DDMONYY[3] = L"A";
            Date_in_DDMONYY[4] = L"Y";
            break;
            case 6:
            Date_in_DDMONYY[2] = L" J";
            Date_in_DDMONYY[3] = L"U";
            Date_in_DDMONYY[4] = L"N";
            break;
            case7:
            Date_in_DDMONYY[2] = L" J";
            Date_in_DDMONYY[3] = L"U";
            Date_in_DDMONYY[4] = L"L";
            break;
            ...
            .
            .
            .
            .

            }

            similar for year
            switch(year/10)
            {
            case 1:
            Date_in_DDMONYY[5] =L"1";
            break;
            case 2:
            }

            switch(year%10)
            {
            case 1:
            Date_in_DDMONYY[6] =L"1";
            break;

            }

            Date_in_DDMONYY[7] ='\0':

            cout<<Date_in_D DMONYY;

            }

            try optimizing..

            Comment

            Working...