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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| Public Function Format(ByVal datFormat, ByVal strFormat)
'Fonction simulant le Format de VB pour les dates
Dim intAnnee
Dim intMois
Dim intJour
Dim intHeure
Dim intMinute
Dim intSeconde
Dim strFormatTemp
'YYYY Années
'MM Mois
'DD Jours
'HH Heures (format 24h)
'hh Heures (format 12h)
'NN Minutes
'SS Secondes
intAnnee = Year(datFormat)
intMois = Month(datFormat)
intJour = Day(datFormat)
intHeure = Hour(datFormat)
intMinute = Minute(datFormat)
intSeconde = Second(datFormat)
Format = vbNullString
intI = 1
Do While intI <= Len(strFormat)
strFormatTemp = vbNullString
Do
strFormatTemp = strFormatTemp & Mid(strFormat, intI, 1)
intI = intI + 1
Loop Until Mid(strFormat, intI, 1) <> Mid(strFormat, intI - 1, 1)
Select Case strFormatTemp
Case "YYYY", "yyyy"
Format = Format & intAnnee
Case "YY", "yy"
Format = Format & Right("00" & intAnnee, 2)
Case "MMMM", "mmmm"
Format = Format & MonthName(intMois, False)
Case "MMM", "mmm"
Format = Format & MonthName(intMois, True)
Case "MM", "mm"
Format = Format & Right("00" & intMois, 2)
Case "M", "m"
Format = Format & intMois
Case "DDDD", "dddd"
Format = Format & WeekDayName(WeekDay(datFormat), False)
Case "DDD", "ddd"
Format = Format & WeekDayName(WeekDay(datFormat), True)
Case "DD", "dd"
Format = Format & Right("00" & intJour, 2)
Case "D", "d"
Format = Format & intJour
Case "HH"
Format = Format & Right("00" & intHeure, 2)
Case "H"
Format = Format & intHeure
Case "hh"
If intHeure > 12 Then
Format = Format & Right("00" & (intHeure - 12), 2)
Else
Format = Format & Right("00" & (intHeure), 2)
End If
Case "h"
If intHeure > 12 Then
Format = Format & (intHeure - 12)
Else
Format = Format & intHeure
End If
Case "NN", "nn"
Format = Format & Right("00" & intMinute, 2)
Case "N", "n"
Format = Format & intMinute
Case "SS", "ss"
Format = Format & Right("00" & intSeconde, 2)
Case "S", "s"
Format = Format & intSeconde
Case Else
Format = Format & strFormatTemp
End Select
Loop
End Function |
Partager