diaeros
diaeros

Reputation: 29

difference between a date and current date

I have a 14 day schedule and instead of memorizing it I wrote this. but I don't know how to get the current date in a format that will work for this program. C++11 is preferred but not required

#include <iostream>
#include <date.h>

using namespace std;

int main()
{
     using namespace date;
    using namespace std;
    auto a = 2012_y/1/24;
    auto b = current date; //I have not figured how to get current date 
    auto c = (sys_days{b} - sys_days{a}).count();
    auto d = c%14
    switch (d) {
    case 1: cout << blank; //blank will be replaced with the schedule
    break;
    case 2: cout << blank;
    break;
    case 3: cout << blank;
    break;
    case 4: cout << blank;
    break;
    case 5: cout << blank;
    break;
    case 6: cout << blank;
    break;
    case 7: cout << blank;
    break;
    case 8: cout << blank;
    break;
    case 9: cout << blank;
    break;
    case 10: cout << blank;
    break;
    case 11: cout << blank;
    break;
    case 12: cout << blank;
    break;
    case 13: cout << blank;
    break;
    case 14: cout << blank;
    break;
    }
    return 0;
}

Upvotes: 0

Views: 86

Answers (1)

Howard Hinnant
Howard Hinnant

Reputation: 218750

It looks like you're using Howard Hinnant's date/time library.

You can get the current date in terms of a sys_days with:

auto b = floor<days>(chrono::system_clock::now());

This will be the current date in UTC. If you need it in a specific time zone, you'll need to use the time zone library (tz.h at the same location you found date.h).

If you're using C++17, floor can be found in <chrono>. Otherwise you can find it in "date.h".

Upvotes: 1

Related Questions