0

Consider this program written in pseudocode:

//Tell program to access the system's date and time

//print just the 'current year', without having to print the entire time,date format.

//Be able to perform calculations with the printed number (for example: 2019), without having to manually enter it anywhere.

My goal is to figure out how to access just a single information like date, month or year and make it a usable operand inside the program to perform operations.

walnut
  • 21,629
  • 4
  • 23
  • 59
  • 3
    Does this answer your question? [Extract year/month/day etc. from std::chrono::time\_point in C++](https://stackoverflow.com/questions/15957805/extract-year-month-day-etc-from-stdchronotime-point-in-c) – walnut Nov 04 '19 at 00:09
  • Also https://stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c – walnut Nov 04 '19 at 00:14
  • @uneven_mark Yes it does! Appreciate the quick response. – Praveen Gunasekaran Nov 04 '19 at 00:25

1 Answers1

2
#include <iostream>
#include <ctime>

int main()
{
    time_t now = time(0);
    tm *ltm = localtime(&now);
    std::cout << "Year = " << 1900 + ltm->tm_year << std::endl;
}

See documentation for ctime.

brj
  • 375
  • 2
  • 11