using to_iso_extended_string with boost date
-
17-01-2021 - |
Domanda
I am trying to convert d2 to a string of the form '2011-08-02' so I can pass this to my sql statement. According to the boost site, to_iso_extended_string should return that format, but I get the following instead: '2011-Aug-02'.
date today(day_clock::local_day());
date_duration dd(30);
date d2=today-dd;
std::string to_iso_extended_string(date d2);
how then do I convert the date to string in the yyyy-mm-dd format.
Soluzione
I have just tested this and it prints 2011-08-02
for me:
#include <iostream>
#include <string>
#include <boost/date_time.hpp>
namespace bg = boost::gregorian;
int
main ()
{
bg::date today (bg::day_clock::local_day());
bg::date_duration dd(30);
bg::date d2 = today - dd;
std::string str(to_iso_extended_string(d2));
std::cout << str << "\n";
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow