Reputation: 587
I have two dates namely the filecreation date and the system date both in the int format as
"20120304","20120404" which is something like YYYYMMDD.
i just want to take the MM part of these two dates these two dates are returned from a function as integers .
Please suggest some examples
Thanks
Upvotes: 0
Views: 262
Reputation: 67221
although i prefer @keety's answer,there is an other way. u can use string streams:
for eg:
#include <sstream>
int i = 5;
std::string s;
std::stringstream out;
out << i;
s = out.str();
so after you have your string as YYYYMMDD
in a string varaible.
substr(4,2)
will be your month.
you can later on use strtol
for converting back to integer.
Upvotes: 0
Reputation: 57774
If they are always in the format YYYYMMDD
, then take the substring at [4] for length 2.
Upvotes: 0