Thread: calculate age from date

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005

    calculate age from date

    Hi guys i have the following code and i am trying to ask for user input and then calculate the users age from the system date. So if the user enters 01/01/1985 and it compares it to the current date it should say that they are 7374 days old. How could i calculate that i am having difficuly i have exstracted the system date already.

    void calage()
     char buff[BUFSIZ];
     char date[12];
     int m,d,y;
     char dateTen;
     char dateUnit;
     char dateTotal;
     struct tm t;
     time_t now;    /* time struct*/
     time(&now);   /* put time into the &now variable*/
     t = *localtime(&now);     /* exstract the system time*/
     strftime(buff, sizeof(buff), "%d//%m//%y", &t); /* format the string*/
     /*printf("m = %d, d = %d, y = %d\n", m, d, y); */
     printf("The current date is %s\n",buff);    /* print the date to the screen*/

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    FAQ > How do I... (Level 2) > Work with dates and times
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. Calc age use Date of PC
    By miziri in forum C++ Programming
    Replies: 12
    Last Post: 03-18-2006, 05:01 AM
  4. casting the system exstracted date into seperate ints
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-30-2005, 12:17 AM