Manipulating system dates

This is a discussion on Manipulating system dates within the C++ Programming forums, part of the General Programming Boards category; Hello programmers, can anyone help me on this? I want to be able to get the current system date add ...

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359

    Manipulating system dates

    Hello programmers, can anyone help me on this? I want to be able to get the current system date add so many days to it or subtract; which will automatically calculate the new date (and also for leap years if possible).

    e.g system date = 02/04/2002 + 29 (days)

    new system date should read 01/05/2002. I've tried using time.h and them annoying structures, but none of them worked. Any help would be very greatful.

    os-win98/builder5

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    I assume you are using Windows. Use the GetSystemTime and SetSystemTime functions for getting and setting the time. If you don't know how to handle them, look it up in your helpfile or in www.msdn.microsoft.com.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    I don't actually want to reset the system time on a computer, I just need to get the date, add or subtract so many days from the date; but it needs to calculate the correct month and days accordingly, perhaps year as well depending on the no of days being added or subtracted.

  4. #4
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359

    sorry...

    this is for console programming....

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    My best code is written with the delete key.

  6. #6
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359

    Unhappy

    Looked at the website, didn't understand it. Can't someone show me an example? It can't be that hard to add so many days to a date, and recalulate the new month etc.

  7. #7
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Why cant people try things on their own? Instead of insisting on us writing code for them. This really smells like homework so ill give you a few suggestions and no code. First using the time_t and calling time(time_t*) will return the number of seconds past since Jan. 1 1970. Well to convert this to the date you just need to get the number of seconds in a year and divide the value returned by time and then you know how many years have passed since then. Or you could use the value returned by time and pass it to ctime and that will return a string in the format: Fri Jan 28 00:00:00 2000. You can extract the date using substrings if you are using strings, then you will have to write your own functions to add days or years or months or whatever you want. Ex:

    Code:
    bool AddToDate(string& strDate, int months, int days, int years);
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  8. #8
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    It's not home work, i left school 6 years ago. 22 at mo, I'm trying to write a program for me and friends. Thanks. And i have been trying to write code myself, just get confused with all the technical jargon.

    Code:
    #include <iostream.h>
    #include <process.h>
    #include <dos.h>
    
    void main()
    {
      struct date reset;
      struct date save_date;
    
      getdate(&save_date);  //Fills in the date structure of the current date
      cout << "Original date:\n";
      system("date"); //Evokes a system command from the os
    
    
      reset.da_year = 2001;
      reset.da_day = 37;
      reset.da_mon = 1;
      setdate(&reset);
    
      cout << "Date after setting:\n";
      system("date");
    
      setdate(&save_date);
      cout << "Back to original date:\n";
      system("date");
    
      getchar();
    }

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >just get confused with all the technical jargon
    So you ask for even more technical source code? Search the web, you'll find thousands of examples with a minimum of effort. It's a waste of our time to repeat code over and over for people who don't bother to do research.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 01:04 PM
  2. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 07:56 PM
  3. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 04:56 PM
  4. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM

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