Thread: Calc age use Date of PC

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    9

    Calc age use Date of PC

    Hi,
    My friend I need to funaction to calc age like this
    example 23 year 2 month and 3 days.

    I will enetr date of birth 1/1/2005 to programme ,
    I want programme which will calc for me age of that person and show me like this.
    his age 1 year 3 month and 15 days.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Exactly what do you have problems with? Showing some coding attempt will most likely motivate people to help rather than flame for asking to do homework.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Do you need help/ideas or do you want someone to write the code for you?
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    9
    Hi,
    my friend i am new in c++.
    i need code how to do it,
    i am very new in this c++
    i know only littlie
    if can writ for all code.
    thx-iraq

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It doesn't get any easier by trying to study what others have done for you.

    At least you should be able to
    - prompt for input
    - read year, month and day values
    - print "You were born on "

    Show us that you can at least do that much.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    9
    Hi,
    friend Thansk for comment Salem,
    Yes correct.
    I want to be compare with pc Date
    I mean like this

    age=(PCdate-dateof birth).

    some like that can plz help out.

    thanx-Iraq

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    Code:
    #include<windows.h>
    #include<iostream>
    using namespace std;
    main(){
    
    SYSTEMTIME st;
           
        GetSystemTime(&st);
    
    cout<<st.wYear;
    }
    here is the code that prints the system year.


    and here is the SYSTEMTIME structure for your reference:
    typedef struct _SYSTEMTIME {
    WORD wYear;
    WORD wMonth;
    WORD wDayOfWeek;
    WORD wDay;
    WORD wHour;
    WORD wMinute;
    WORD wSecond;
    WORD wMilliseconds;
    } SYSTEMTIME


    so u can use whicever field u want.actually i am still using the c api,if u want c++ wrapper classes refer to mfc(CTime class).

    can u do it from here or u want more help?
    Last edited by qqqqxxxx; 03-17-2006 at 12:53 AM.

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by miziri
    Hi,
    friend Thansk for comment Salem,
    Yes correct.
    I want to be compare with pc Date
    I mean like this

    age=(PCdate-dateof birth).

    some like that can plz help out.

    thanx-Iraq

    In C there is no magic or standard way to do what you want. In C++ there are classes that will take two dates and return the difference.

    The functions in time.h should help you. time() will return current system date as an unsigned integer. Then convert the birth date to struct tm and call mktime() which will return the values of struct tm into an integer. Then just subract the two integers. That will give you the difference in seconds. Finally convert the difference into years, months and days.

  10. #10
    Registered User
    Join Date
    Mar 2006
    Posts
    9
    Hi Ancient Dragon ,
    Thank can plz If you can code to all you explain
    I will thansk full to you.
    if your write for me.

    thx

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Show some effort will you!

    You do the work, we help you sort out the problems - you're never going to learn anything by just begging people to do the work for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Registered User
    Join Date
    Mar 2006
    Posts
    9
    Hi,
    Salem Thanks,but my friend I also try from my side to out with solution.
    but this first time for to work with date in c++

    thx

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    5 posts of begging.
    Not a single line of code showing any attempt at anything.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  3. calculate age from date
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-22-2005, 08:57 AM
  4. How to calc. your age in days..?
    By Gugge in forum C Programming
    Replies: 7
    Last Post: 03-13-2002, 03:40 AM