+ 2

What is the code to get the present system date in C++ program???

I m creating a program in which it's needed to compare 2 dates one which is entered by user and another the present date... So how can i get present system date as i don't want present system date to be entered by user also... Pls help..!!!

7th Mar 2017, 7:54 PM
Saksham Johri
Saksham Johri - avatar
1 Answer
+ 1
#include <ctime> #include <iostream> using namespace std; int main() { time_t t = time(0); // get time now struct tm * now = localtime( & t ); cout << (now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday << endl; } check it here https://code.sololearn.com/cBxfHjtw2N8W/#cpp
7th Mar 2017, 8:11 PM
Meher Jebali
Meher Jebali - avatar