Apr 9, 2013 at 2:55pm UTC
Hi dudes!
i am working on a library system. If issue date is current date, the due date will be the date after 14 days of current date. i am unable to make the algorithm for calculation of due date. kindly guide me.
Last edited on Apr 9, 2013 at 2:55pm UTC
Apr 9, 2013 at 4:24pm UTC
Playing with
chrono :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <chrono> //Looks like chrono includes ctime as well
#include <iostream>
int main()
{
using std::chrono::system_clock;
auto issue_date(std::chrono::system_clock::now());
auto due_date = issue_date + std::chrono::hours(24*14);
std::time_t issue_date_o(system_clock::to_time_t(issue_date));
std::time_t due_date_o(system_clock::to_time_t(due_date));
char mbstr[100];
if (std::strftime(mbstr, 100, "%d %B %Y" , std::localtime(&issue_date_o)))
std::cout << "issued on: " << mbstr << '\n' ;
if (std::strftime(mbstr, 100, "%d %B %Y" , std::localtime(&due_date_o)))
std::cout << "due date: " << mbstr;
}
EDIT : if you want to use only
time_t and
ctime :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <ctime>
#include <iostream>
int main()
{
std::time_t issued = std::time(NULL);
std::tm due_tm = *std::localtime(&issued);
due_tm.tm_mday += 14;
std::time_t due = std::mktime(&due_tm);
char mbstr[100];
if (std::strftime(mbstr, 100, "%d %B %Y" , std::localtime(&issued)))
std::cout << "issued on: " << mbstr << '\n' ;
if (std::strftime(mbstr, 100, "%d %B %Y" , std::localtime(&due)))
std::cout << "due to: " << mbstr << '\n' ;
}
Last edited on Apr 9, 2013 at 5:14pm UTC