cs_JMO
Messages postés
1854
Date d'inscription
jeudi 23 mai 2002
Statut
Membre
Dernière intervention
24 juin 2018
27
29 avril 2006 à 09:35
Bonjour,
Comme le préconise "mcs2006", exemple détaillé ci-dessous avec DateDiff.
Dim Saisie, DateEntree, DateSortie, Msg, n, hh, mn
Saisie = InputBox(vbCrLf&vbCrLf&vbCrLf&vbCrLf&"Saisir votre date sous la forme:"_
&vbCrLf&vbCrLf&"jj/mm/aaaa hh:mm - jj/mm/aaaa hh:mm"&vbCrLf&"Remplacer les 5 derniers caractères hh:mm",_
"Calcul d'intervalle de temps en minutes", Left(Now, 16) & " - " & Left(Now, 10) & " 00:15")
DateEntree = Mid(Saisie, 1, 16) & ":00"
DateSortie = Mid(Saisie, 20, 16) & ":00"
' y = DateDiff("yyyy", DateSortie, DateEntree) ' aaaa
' m = DateDiff("m", DateSortie, DateEntree) ' mm
' d = DateDiff("y", DateSortie, DateEntree) ' jj
' h = DateDiff("h", DateSortie, DateEntree) ' hh
' n = DateDiff("n", DateSortie, DateEntree) ' mn
' s = DateDiff("s", DateSortie, DateEntree) ' ss
n = DateDiff("n" , DateSortie, DateEntree)
Temps = n * 60 'temps en secondes
hh = Temps / 3600
mn = (hh - Int(hh)) * 60
If hh >= 24 Then
jj = Int(hh / 24)
hh = hh - jj * 24
End If
Conversion = Int(jj) & " j " & Int(hh) & " h " & CInt(mn) & " mn"
Msg = "Comparaison de dates du " & DateSortie & " au " & DateEntree &vbCrLf&vbCrLf
Msg = Msg & "La différence entre les 2 dates est : " &vbCrLf&vbCrL
Msg Msg & "Nombre total en minutes " & n &vbCrLf&vbCrLf
MsgBox s & " " & Msg &vbCrLf& " soit: " & Conversion,_
vbApplicationModal + vbDefaultButton1 + vbInformation + vbOKOnly, "Résultat"
If n =0 Then
MsgBox "Les dates à comparer sont identhiques"
InputBox Saisie , "Calcul d'intervalle de temps en minutes", Left(Now, 16) &" - " & Left(Now, 11) & " 00:00"', Left(Now, 16) & " - " & Left(Now, 10) & " 00:00", "Calcul d'intervalle de temps en minutes", Left(Now, 16) & " - " & Left(Now, 11) & " 00:00"
Else
Msg = "Comparaison de dates du " & DateSortie & " au " & DateEntree &vbCrLf&vbCrLf
Msg = Msg & "La différence entre les 2 dates est : " &vbCrLf&vbCrLf
Msg Msg & "Nombre total en minutes " & n &vbCrLf&vbCrLf
Msg Msg & "Nombre de jours " & Int(jj)&vbCrLf&vbCrLf
Msg Msg & "Nombre de heures " & Int(hh)&vbCrLf&vbCrLf
Msg Msg & "Nombre de minutes " & CInt(mn)
MsgBox Msg '& "La différence entre les 2 dates est : " &vbCrLf&vbCrLf& Msg
End If
jean-marc