0

Hi I have two strings:

entertime "2014-03-06T09:35:36Z" 
exittime "2014-03-06T09:38:36Z" 

I want to be able to return the difference, which in this case should return 3min.

My method looks like this:

 boost::gregorian::date returnTime(std::string entertime, std::string exittime){
 boost::gregorian::date denter = boost::gregorian::from_string(entertime);
 boost::gregorian::date dexit = boost::gregorian::from_string(entertime);
 boost::gregorian::date dresult = dexit-denter;

Is there any way to get this time difference?

Thank you in advance!

R. Barzell
  • 666
  • 5
  • 24

1 Answers1

1

Unfortunately there is no direct converter for your particular timestamp, if you could remove all the delimiters and form a string which meets the iso spec, then you can do the below:

  auto ts1 = boost::posix_time::from_iso_string("20140306T093536Z");
  auto ts2 = boost::posix_time::from_iso_string("20140306T093836Z");

  std::cout << (ts2 - ts1) << std::endl;

This should output 00:03:00 as you expect. NOTE The types here are (ts1 & ts2 are boost::posix_time::ptime and the delta is a boost::posix_time::time_duration)

Nim
  • 33,299
  • 2
  • 62
  • 101