Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Parsing is usually done on streams, not strings, but you can use a <code>stringstream</code>.</p> <pre><code>std::istringstream date_s( "04\\10\\1984" ); struct tm date_c; date_s &gt;&gt; std::get_time( &amp;date_c, "%d\\%m\\%Y" ); std::time_t seconds = std::mktime( &amp; date_c ); </code></pre> <p>Now you can compare seconds using <code>&lt;</code> to determine which was earlier.</p> <p>Note, <a href="http://en.cppreference.com/w/cpp/io/manip/get_time" rel="nofollow noreferrer"><code>std::get_time</code></a> is new in C++11. It is defined in terms of <code>strptime</code>, which is from POSIX but not part of the C99 standard. You can use <a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html" rel="nofollow noreferrer"><code>strptime</code></a> if a C++11 library is not available. If you're brave, you can also use the <code>std::time_get</code> facet… it's ugly though.</p> <p>If you don't want to know anything about the dates other than which is earlier, you can use <code>std::lexicographical_compare</code>. It would be a one-liner but the function name is so long.</p> <pre><code>// return true if the date string at lhs is earlier than rhs bool date_less_ddmmyyyy( char const *lhs, char const *rhs ) { // compare year if ( std::lexicographical_compare( lhs + 6, lhs + 10, rhs + 6, rhs + 10 ) ) return true; if ( ! std::equal( lhs + 6, lhs + 10, rhs + 6 ) ) return false; // if years equal, compare month if ( std::lexicographical_compare( lhs + 3, lhs + 5, rhs + 3, rhs + 5 ) ) return true; if ( ! std::equal( lhs + 3, lhs + 5, rhs + 3 ) ) return false; // if months equal, compare days return std::lexicographical_compare( lhs, lhs + 2, rhs ); } </code></pre> <p>See also <a href="https://stackoverflow.com/questions/1002542/how-to-convert-datetime-to-unix-timestamp-in-c">how to convert datetime to unix timestamp in c?</a> .</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload