bool is_same_week(int date1, int date2) { if(abs(date1 - date2) >= 7) { return false; } int week = 0; struct tm t = {0}; t.tm_year=date1/10000-1900; t.tm_mon=date1/100%100-1; t.tm_mday=date1%100; t.tm_hour=0; t.tm_min=0; t.tm_sec=0; t.tm_isdst=0; time_t day_time_t1 = mktime(&t); struct tm t1 = {0}; localtime_r(&day_time_t1, &t1); week = t1.tm_wday; if(week == 0) { week = 7; } day_time_t1 -= (week-1)*24*3600; t.tm_year=date2/10000-1900; t.tm_mon=date2/100%100-1; t.tm_mday=date2%100; t.tm_hour=0; t.tm_min=0; t.tm_sec=0; t.tm_isdst=0; time_t day_time_t2 = mktime(&t); struct tm t2 = {0}; localtime_r(&day_time_t2, &t2); week = t2.tm_wday; if(week == 0) { week = 7; } day_time_t2 -= (week-1)*24*3600; return (day_time_t1 == day_time_t2); } int main() { if (is_same_week(20161206, 20161212)){ cout << "is same week" << endl; } return 0; }