Pescador34
March 17th, 2005, 08:49 AM
Title ??? :)
|
Click to See Complete Forum and Search --> : How to find difference between two dates dd/mm/yyyy? Pescador34 March 17th, 2005, 08:49 AM Title ??? :) cilu March 17th, 2005, 09:47 AM COleDateTime t1(2005,3,17,0,0,0); COleDateTime t2(2004,3,1,0,0,0); COleDateTimeSpan ts = t1 - t2; Bni March 17th, 2005, 09:59 AM difftime: Computes the difference between two times. mktime: Converts time to calendar format. Pescador34 March 17th, 2005, 11:02 AM Thanks, i use it but to separate dates i make this int HelpingHand::DifferenceBetweenDates(char *date1,char *date2){ int day1,month1,year1,day2,month2,year2; int totalsep = 0, i = 0, j = 0 ; char num[4]; ZeroMemory(num, sizeof(num)); while(date1[i] != '\0'){ TRACE("%c",date1[i]); if ( totalsep == 0 && (date1[i] == '-' || date1[i] == '/')){ day1 = atoi(num); ZeroMemory(num, sizeof(num)); totalsep += 1; j=0; i++; continue; }else if(totalsep == 1 && (date1[i] == '-' || date1[i] == '/')){ month1 = atoi(num); ZeroMemory(num, sizeof(num)); totalsep += 1; j=0; i++; continue; } num[j] = date1[i]; i++; j++; } year1 = atoi(num); ZeroMemory(num, sizeof(num)); totalsep = 0; i=0; j=0; TRACE("\n"); while(date2[i] != '\0'){ TRACE("%c",date2[i]); if ( totalsep == 0 && (date2[i] == '-' || date2[i] == '/')){ day2 = atoi(num); ZeroMemory(num, sizeof(num)); totalsep += 1; j=0; i++; continue; }else if(totalsep == 1 && (date2[i] == '-' || date2[i] == '/')){ month2 = atoi(num); ZeroMemory(num, sizeof(num)); totalsep += 1; j=0; i++; continue; } num[j] = date2[i]; i++; j++; } year2 = atoi(num); ZeroMemory(num, sizeof(num)); COleDateTime t1(year1,month1,day1,0,0,0); COleDateTime t2(year2,month2,day2,0,0,0); COleDateTimeSpan ts = t2 - t1; return ts; } do you can know more simple ;). Thanks again. difftime: Computes the difference between two times. mktime: Converts time to calendar format. Time? Data.... Pescador34 March 17th, 2005, 12:49 PM In another form.... date if give like: dfCreated = 16-03-2005 11:17:28 dNow = 17-03-2005 18:41:20 i try to use this... int HelpingHand::DifferenceBetweenDates(char *dfCreated,char *dNow){ CTime diff = (dNow - dfCreated); CString stemp = diff.Format( "Total days: %D, hours: %H, mins: %M, secs: %S" ); ... output = Total days: , hours: 00, mins: 01, secs: 12 !!!!!!! sorry the confusion...:o Bni March 17th, 2005, 04:12 PM What I had in mind was more like... #include <stdio.h> #include <time.h> #define EXTRACT_HOUR(sec) ((sec)/(60*60)) int main(void) { time_t t1, t2, t3; struct tm datetime; datetime.tm_year = 2005 - 1900; datetime.tm_mon = 03 - 1; datetime.tm_mday = 17; datetime.tm_hour = 1; datetime.tm_min = 2; datetime.tm_sec = 3; datetime.tm_isdst = 0; t1 = mktime(&datetime); printf("Date and time #1: %s\n", ctime(&t1)); datetime.tm_year = 2005 - 1900; datetime.tm_mon = 03 - 1; datetime.tm_mday = 17; datetime.tm_hour = 8; datetime.tm_min = 7; datetime.tm_sec = 6; datetime.tm_isdst = 0; t2 = mktime(&datetime); printf("Date and time #2: %s\n", ctime(&t1)); t3 = t2-t1; printf("Total number of seconds : %ld \n", t3); printf("Relative number of hours is: %ld heures\n", EXTRACT_HOUR(t3) ); return 0; } I dont know any shorter codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |