Results 1 to 2 of 2

Thread: convert string to date

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    In C++, does anyone know how to convert a string to a date, or extract integers representing the date? My string would be something like:

    Code:
    string sdate = "01012000";
    I want to extract 1, 1, 2000 into three separate ints.

    [Edited by wey97 on 11-08-2000 at 04:42 PM]

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Talking

    OK, I figured it out myself:

    Code:
    string sdate = "01012000";
    int month, day, year;
       
          month = 10*int(sdate[0]-'0') + int(sdate[1]-'0');
          day = 10*int(sdate[2]-'0') + int(sdate[3]-'0');
          year = 1000*int(sdate[4]-'0') + 100*int(sdate[5]-'0') + 10*int(sdate[6]-'0')+ int(sdate[7]-'0');

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width