date

This is a discussion on date within the C++ Programming forums, part of the General Programming Boards category; I have some troubles on working with dates. I can get the current date, and I can read in the ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    1

    Question date

    I have some troubles on working with dates. I can get the current date, and I can read in the date wanted into a char (string), but I am unable to calculate the difference between these two dates. I hope someone can help me.
    Suggestions can always be sent to stephanespeel@hotmail.com

  2. #2
    Unregistered
    Guest
    depends on what time functions you are using. If you are using time.h or ctime header files look up difftime(), which returns the number of seconds between two different times, which can they be translated into minutes, hours, days, weeks, years, decades, centuries; whatever, with a little tweaking.

  3. #3
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    I hope this isn't another... please answer my questions, but I will never be back so make sure that you email them to me... post.

    What do you guys think?
    Blue

  4. #4
    Unregistered
    Guest

    Question no this isn't such a ...

    Look, I'm sorry if you have a wrong impression of me, but I surely have no wrong intentions with this.

    I am studying the C++ language, and my professors didn't know the answer eather. I'm already visiting this site since a year, and I admit, only now I have registered.

    But this is not only to solve my own problems, if I can be of any help to one of you, you may always call on me, than I see what I can do about it.

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    There is a function in time.h or ctime to do what you want. It is called difftime(). Go look it up in your helpfiles. come back if you still cant manage with your attempt so that we can show you how to fix it.

    oops unregistered has already told you about it.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Unregistered
    Guest
    fair enough, but posting questions/ideas/answers to the board helps more than one person at a time (potentially at least). Therefore many people don't send email responses and don't go to another site to look at code people are having problems with. You will get the most responses, for better or worse, by posting publically.

  7. #7
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    I'd use tm structs and mktime(). Then you can manipulate the information easily.

    1. Get user date
    2. Create a tm struct with the user's date
    3. Use mktime() to fill in things for you (tm_yday specifically)
    3. use localtime() to fill in a tm struct for the current date
    4. Calculate the differences you need using the tm structs

    HINT: for the difference in days look at tm_yday.
    Last edited by taylorguitarman; 02-14-2002 at 12:20 PM.
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    Your professor didn't know how to do this???? And he is a professor in what???

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. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 04:23 PM
  4. CDate Class - handle date manipulation simply
    By LuckY in forum C++ Programming
    Replies: 5
    Last Post: 07-16-2003, 08:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21