Admin Admin
Nombre de messages : 138 Age : 38 Date d'inscription : 02/09/2006
| Sujet: Calculer le numero de semaine d'une date avec C Mer 13 Sep - 5:01 | |
| - Code:
-
//____________________________________________________________________ // // Retourne le numero de semaine [1 ... 53], 0 si erreur //____________________________________________________________________ // int Semaine(int j, int m, int a) { int s = 0; struct tm tmj = {0, 0, 12, 1, 0, a - 1900}; struct tm tmq = {0, 0, 12, j, m - 1, a - 1900}; if(mktime(&tmj) != (time_t)-1 && mktime(&tmq) != (time_t)-1) { if(!(s = (tmj.tm_wday + tmq.tm_yday + 6) / 7 - (tmj.tm_wday / 5))) s = Semaine(31, 12, a - 1); if(m == 12) { int js = (tmj.tm_wday + tmq.tm_yday) % 7; if((js == 1 && (j >= 29 && j <= 31)) || (js == 2 && (j == 30 || j == 31)) || (js == 3 && j == 31)) s = 1; } } return s; }
| |
|