-2

I did not find any solution which give the only date. I found the solution but all are complex and we have to parse the array and separate the date from time

sss
  • 31
  • 1
  • 2

3 Answers3

2

Try to this

#include <iostream>
#include <iomanip>
#include <ctime>

int main()
{
    auto t = std::time(nullptr);
    auto tm = *std::localtime(&t);
    std::cout << std::put_time(&tm, "%d-%m-%Y %H-%M-%S") << std::endl;
}
Haresh Shyara
  • 1,826
  • 10
  • 13
1

If you run the following code, today then you will find the current date in following format.

04/14/15

#include<iostream>
#include<ctime>
using namespace std;
int main()
{
 char c[9];
 _strdate_s(c);
 cout<<c<<endl;
 return 0;
}
sss
  • 31
  • 1
  • 2
0

ideone code

#include <iostream>
#include <ctime>
using namespace std;

int main() 
{
    time_t now = time(0);

   tm *ltm = localtime(&now);

   cout << "Year: "<< 1900 + ltm->tm_year << endl;
   cout << "Month: "<< 1 + ltm->tm_mon<< endl;
   cout << "Day: "<<  ltm->tm_mday << endl;
}
utarid
  • 1,642
  • 4
  • 24
  • 38