Any Genius who give me Cpp code for count no.ofdays in two different dates of different years | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Any Genius who give me Cpp code for count no.ofdays in two different dates of different years

Its hard but for inteligent it's easy

13th Dec 2016, 6:49 PM
Aadil Sayyed
Aadil Sayyed - avatar
3 Answers
+ 2
To take user input you would have to parse the string into a 'tm' struct. Try something like: char *input = "24/12/2016"; struct tm t1; strptime(input, "%D", &t1);
14th Dec 2016, 8:06 AM
Kerrash
Kerrash - avatar
+ 1
#include <iostream> #include <ctime> using namespace std; int main() { struct tm t1 = {0,0,0,24,12,114}; struct tm t2 = {0,0,0,2,7,116}; time_t date1 = mktime(&t1); time_t date2 = mktime(&t2); double diff = difftime(date2, date1) / (3600 * 24); cout << diff << " days" << endl; cout << ctime(&date1); cout << ctime(&date2); return 0; }
13th Dec 2016, 8:08 PM
Kerrash
Kerrash - avatar
0
Can we accept dates from user
14th Dec 2016, 7:31 AM
Aadil Sayyed
Aadil Sayyed - avatar