DATEDIFF - THE TRUTH

P

POL

Function STJ(ndt As Date, kdt As Date, vid As Integer) As String
Dim ndden, ndmes, ndgod, kdden, kdmes, kdgod, dni, mes, god As Integer
' vid ñå âàäè ïðè èç÷èñëÿâàíåòî - ò.å. àêî ñå íàïèøå êàòî â òð. êí. \1\ ñå
èç÷. äî ïðåä. äåí
If ndt >= kdt Then
MsgBox ("Ãðåøíî çàäàäåíè äàòè")
Exit Function
End If
Dim ndtt, kdtt As String
ndtt = Format(ndt, "mmddyyyy")
kdtt = Format(kdt, "mmddyyyy")
'MsgBox ndtt
'MsgBox kdtt
ndmes = Val(Left(ndtt, 2))
kdmes = Val(Left(kdtt, 2))
ndden = Val(Mid(ndtt, 3, 2))
kdden = Val(Mid(kdtt, 3, 2))
ndgod = Val(Right(ndtt, 4))
kdgod = Val(Right(kdtt, 4))
If ndgod = kdgod Then
god = 0
If kdden >= ndden Then
mes = kdmes - ndmes
dni = kdden - ndden
Else
mes = kdmes - ndmes - 1
dni = (dnimes(ndmes, ndgod) - ndden + vid) + kdden - vid
End If
STJ = Format(god, "00") + Format(mes, "00") + Format(dni, "00")
Exit Function
Else
If kdden >= ndden Then
dni = kdden - ndden
If kdmes >= ndmes Then
god = kdgod - ndgod
mes = kdmes - ndmes
Else
god = kdgod - ndgod - 1
mes = kdmes + (12 - ndmes)
If mes = 12 Then
god = god + 1
mes = 0
End If
End If
Else 'íà÷àëåí äåí å ïî-ãîëÿì îò êð. äåí
dni = (dnimes(ndmes, ndgod) - ndden + vid) + kdden - vid
If kdmes > ndmes Then
mes = kdmes - ndmes - 1
god = kdgod - ndgod
Else
god = kdgod - ndgod - 1
mes = kdmes + (12 - ndmes)
If mes = 12 Then
god = god + 1
mes = 0
End If
End If
End If
STJ = Format(god, "00") + Format(mes, "00") + Format(dni, "00")
Exit Function
End If
STJ = Format(god, "00") + Format(mes, "00") + Format(dni, "00")
End Function
 
J

John Vinson

Function STJ(ndt As Date, kdt As Date, vid As Integer) As String
Dim ndden, ndmes, ndgod, kdden, kdmes, kdgod, dni, mes, god As Integer
' vid ñå âàäè ïðè èç÷èñëÿâàíåòî - ò.å. àêî ñå íàïèøå êàòî â òð. êí. \1\ ñå
èç÷. äî ïðåä. äåí
If ndt >= kdt Then

POL, is this a suggestion, a question, an answer, or what? I have no
idea what you're posting.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top