#include <iostream>
#include <vector>
#include <chrono>
// Function to format the date as a string
std::string formatDate(const std::chrono::system_clock::time_point& tp) {
std::time_t time = std::chrono::system_clock::to_time_t(tp);
std::tm* tm = std::localtime(&time);
char buffer[11]; // 2025-04-10 // 10 chars + null
std::strftime(buffer, sizeof(buffer), "%Y-%m-%d", tm);
return std::string(buffer);
}
int main() {
// Get today's date
auto today = std::chrono::system_clock::now();
// Create a vector to store the dates
std::vector<std::string> dates;
// Fill the vector with dates from today going back 30 days
for (int i = 0; i < 30; ++i) {
auto date = today - std::chrono::hours(24 * i);
dates.push_back(formatDate(date));
}
for (const auto& date : dates) {
std::cout << date << std::endl;
}
}
/*
run:
2025-04-10
2025-04-09
2025-04-08
2025-04-07
2025-04-06
2025-04-05
2025-04-04
2025-04-03
2025-04-02
2025-04-01
2025-03-31
2025-03-30
2025-03-29
2025-03-28
2025-03-27
2025-03-26
2025-03-25
2025-03-24
2025-03-23
2025-03-22
2025-03-21
2025-03-20
2025-03-19
2025-03-18
2025-03-17
2025-03-16
2025-03-15
2025-03-14
2025-03-13
2025-03-12
*/