How to print the date of yesterday?

rin67630
Posts: 141
Joined: Sun Mar 11, 2018 5:13 pm

How to print the date of yesterday?

Postby rin67630 » Sat Feb 03, 2024 1:46 pm

Hi
I have a program that issues at midnight the summary of the past day.
It should issue the summary in a line appended to a file. That file should be in the csv format, for post processing in Excel.
All is done now.

But I would like to begin the line with a date identifier. Only day/month. And that identifier should be the day of yesterday (because I print after midnight)
Has someone got an idea how to code that in c++?

Thank you for any hint...

rin67630
Posts: 141
Joined: Sun Mar 11, 2018 5:13 pm

Re: How to print the date of yesterday?

Postby rin67630 » Sat Feb 03, 2024 9:39 pm

Finally I found out alone.
  1. //***Variables for Time***
  2. tm* timeinfo;  
  3. tm* yesterdaytimeinfo;  
  4. time_t now;
  5. time_t yesterdaynow;
  6. static char charbuff[120];  //Char buffer for many functions
  7.  
  8.  
  9. //*** In program ***
  10. yesterdaynow = now - 86400;
  11. yesterdaytimeinfo = localtime(&yesterdaynow);
  12. strftime(charbuff, 30, "%x ", yesterdaytimeinfo);
  13. println();
  14. print(charbuff);
Enjoy!

Who is online

Users browsing this forum: No registered users and 40 guests