J'ai trouver pas mal de fonction qui donne le nombre de jour écouler entre deux date mais je n'ai trouver nul part d'algorithme donnant la réponse sous forme JJ MM AA.
J'apporte donc ma (petite) pierre à l'édifice .
Attention toutefois que je n'ai pas mis de test de garde .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46 internal static int[] GetDatePassed(DateTime pDate) { DateTime Date = pDate; TimeSpan Tampon = new TimeSpan(1, 0, 0, 0); int Day = 0, Month = 0, Year = 0, DataMonth = 0; while (Date.Date != DateTime.Now.Date) { Date += Tampon; DataMonth = Date.Month - 1; if (DataMonth == 0) DataMonth = 12; Day++; if (Day >= 28 && DataMonth == 2) { if (Date.Year %4 !=0 || (Date.Year %100 == 0 && Date.Year%400 != 0)) { Day = 0; Month++; } if (Day == 29) { Day = 0; Month++; } } else if (Day == 30 && (DataMonth == 4 || DataMonth == 6 || DataMonth == 9 || DataMonth == 11)) { Day = 0; Month++; } else if (Day == 31) { Day = 0; Month++; } if (Month == 12) { Month = 0; Year++; } } if (Day == 30 && (DataMonth == 4 || DataMonth == 6 || DataMonth == 9 || DataMonth == 11)) { Day = 0; Month++; } return new int[] { Day, Month, Year }; }
Partager