Search code examples
c++datetimeboostgraphlabsframe

Cannot parse datetime in pm format with booster, C++, graphlab


I've tried to convert datetime string into datetime of an SArray (uses C++ booster library), but it does not seem to understand the %p format specifier. http://www.boost.org/doc/libs/1_43_0/doc/html/date_time/date_time_io.html This documentation says specifiers marked with ! do not currently work for input. Does that mean that you cannot parse anything with pm or PM?enter image description here


Solution

  • I was able to get the string-to-datetime conversion to work by making two small changes:

    1. Use %I for the hour on a 12-hour clock (%H is for a 24 hour clock).
    2. Use %P (upper case) for the AM/PM flag.

    Here's what works for me:

    sf = gl.SFrame({'date': ['2015-11-06 02:12:42 pm', 
                             '2015-11-05 03:43:11 pm']})
    sf['date2'] = sf['date'].str_to_datetime('%Y-%m-%d %I:%M:%S %p')