Finding the time between two dates?

Hey, I need to find the amount of years, months, and days between two dates. The first date comes from the user while the second is from the current date. I am lost on how to get the month day and year out of ctime. It shows as sep 10 2014 but I need september as a number. My professor hinted at converting the char dt into a string and then using substr to get the values. I can get day and year but I don't know how to get month.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  #include <iostream>
#include <ctime>
#include <string>
using namespace std;

int main(){

	int month;
	int day;
	int year;

	// current date/time based on current system
	time_t now = time(0);

	// convert now to string form
	char* dt = ctime(&now);

	//convert dt to string and use substring to get day month and year
	string mystring = string(dt);
	string strDay = mystring.substr(8,2);
	string strYear = mystring.substr(20,4);
	


	//Prompt user to enter date
	cout << "Enter the date when the customer opened the account(MM/DD/YYYY): ";
	cin >> month >> d >> day >> d >> year;

	cout << "Hello world !! Current date and time is: " << dt << endl;
	system("Pause");
	return 0;
}
Topic archived. No new replies allowed.