upcoming date function

hi!


i need some help with the date stuff.

i'm working on a library system, and i need both current date (date of the loan) and the date 4 weeks from now (that day one is to return a book), and return them both as strings.

how do i resolve this?



thanks in advance :)

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
    time_t rawtime;
    struct tm* timeinfo;
    string today;
    string due_date;
    char* buf=new char [1024];

// Get the number of seconds since 1 January, 1970
    rawtime=time(NULL);
// Convert to a local time and date
    timeinfo=localtime(&rawtime);
// Convert to string
    strftime(buf,1024,"%A, %d %B %Y",timeinfo);
    today=buf;
    delete [] buf;
    buf=new char [1024];
// Add 4 weeks
    rawtime+=4*(7*86400);
// Convert to local time and date
    timeinfo=localtime(&rawtime);
// Convert to string
    strftime(buf,1024,"%A, %d %B %Y",timeinfo);
    due_date=buf;
    cout << "Today is: " << today;
    cout << endl;
    cout << "Your book(s) are due back on: " << due_date;
    cout << endl;
    system("pause");
}


Basically this takes the current time and turns it into a date string, then adds 2419200 seconds (4 weeks worth) and turns that into a date.
awesome :) thanks a lot m8!
Topic archived. No new replies allowed.