title: How to convert a boost::ptime to string
body: <p>I'm having trouble converting a ptime object from boost into a string to be passed in to a function. I have found multiple similar other threads in regards to outputing a boost time object to a string (mostly to cout) but none of what I've found on them are working. </p>
  
  <p>It appears the easiest way is inserting the ptime object into a stringstream and then using the stringstream's string. I have also attempted to imbue the stringstream with a time_facet, as some of the answers on other threads suggest. However, I am unable to create a time_facet object. It gives me the error that the argument list for the class template is missing. What is confusing is the nowhere on the internet have I found any mention of an argument list for time_facet, and even boost's documentation page shows that the default constructor for a time_facet is merely time_facet().</p>
  
  <p>Below is a simple version of what I have tried:</p>
  
  <pre><code>#include &lt;boost/date_time/posix_time/posix_time.hpp&gt;
  #include &lt;boost/date_time/posix_time/posix_time_io.hpp&gt;
  
  boost::posix_time::ptime time = boost::posix_time::time_from_string("1981-08-20 08:05:00"); 
  std::stringstream sstream;
  sstream &lt;&lt; time;
  _updateStatement-&gt;setString(1, (sql::SQLString)sstream.str());
  </code></pre>
  
  <p>The insertion of time into the stringstream gives me a bunch of compilation errors in the vein of </p>
  
  <pre><code>error C2220: warning treated as error - no 'object' file generated C:\code\trunk\Development\External\boost\include\boost/date_time/time_facet.hpp(247) :while compiling class template member function 'boost::date_time::time_facet&lt;time_type,CharT&gt;::time_facet(size_t)'
            with
            [
                time_type=boost::posix_time::ptime,
                CharT=char
            ]
  </code></pre>
  
  <p>despite the fact that I haven't used any time_facet objects.</p>
  
  <p>When I DO try to do this with a time_facet object, I add in </p>
  
  <pre><code>sstream.imbue(std::locale(sstream.getloc(), new boost::date_time::time_facet("%Y-%m-%d %H:%M:%S")));
  </code></pre>
  
  <p>before inserting the time into the stringstream. The errors for that are that it wants an argument list as mentioned at the top of this post.</p>
  
  <p>Is there perhaps a function in boost that is the reverse of boost::posix_time::time_from_string()? If not, any other help would be appreciated. Thank you.</p>