اذهب الي المحتوي
أوفيسنا

الردود الموصى بها

قام بنشر (معدل)

كيفية إستدعاء دالة الفرق بين تارخين في الإستعلام إليكم الدالة

Function Calcdiffy(vdate1 As Date, vdate2 As Date)
Dim vyears As Integer, vMonths As Integer, vDays As Integer
vMonths = DateDiff("m", vdate1, vdate2)
vDays = DateDiff("d", DateAdd("m", vMonths, vdate1), vdate2)
If vDays < 0 Then
    vMonths = vMonths - 1
    vDays = DateDiff("d", DateAdd("m", vMonths, vdate1), vdate2)
End If
vyears = vMonths \ 12
vMonths = vMonths Mod 12
Calcdiffy = vyears
End Function

Function CalcdiffM(vdate1 As Date, vdate2 As Date)
Dim vyears As Integer, vMonths As Integer, vDays As Integer
vMonths = DateDiff("m", vdate1, vdate2)
vDays = DateDiff("d", DateAdd("m", vMonths, vdate1), vdate2)
If vDays < 0 Then
    vMonths = vMonths - 1
    vDays = DateDiff("d", DateAdd("m", vMonths, vdate1), vdate2)
End If
vyears = vMonths \ 12
vMonths = vMonths Mod 12
CalcdiffM = vMonths
End Function

Function CalcdiffD(vdate1 As Date, vdate2 As Date)
Dim vyears As Integer, vMonths As Integer, vDays As Integer
vMonths = DateDiff("m", vdate1, vdate2)
vDays = DateDiff("d", DateAdd("m", vMonths, vdate1), vdate2)
If vDays < 0 Then
    vMonths = vMonths - 1
    vDays = DateDiff("d", DateAdd("m", vMonths, vdate1), vdate2)
End If
vyears = vMonths \ 12
vMonths = vMonths Mod 12
CalcdiffD = vDays
End Function

 

 

تم تعديل بواسطه jjafferr
إظهار الكود بالطريقة الصحيحة بإستعمال زر <> من القائمة
قام بنشر

تكتب اسم الدالة في منشئ التعبير هكذا :

Calcdiffy(vdate1 As Date, vdate2 As Date)

بعدها تقوم بوضع المتغيرات ..  vdate1 و vdate2

  • أفضل إجابة
قام بنشر

طيب ايش رأيك بهذه النتيجة : 2س/1ش/0ي  = 2 سنه/1 شهر/ 0 يوم :

image.png.d4ccac396a221b0eacccc74668280772.png

 

image.png.9246804b5683e15719101a07920ccd20.png

 

وهذه هي الدالة:

Public Function YMDDif4(sDate1, sDate2)
On Error GoTo err_YMDDif4


    'sDate1 earliest date
    'sDate2 later date
    
    Dim D As Integer, m As Integer, y As Integer
    
    Dim iYear As Integer
    Dim iMonth As Integer
    Dim iDay As Integer
    Dim dInterim1 As Date
    
    iMonth = DateDiff("m", sDate1, sDate2)
        
    If Day(sDate1) > Day(sDate2) Then
        iMonth = iMonth - 1
    End If
    
    dInterim1 = DateAdd("m", iMonth, sDate1)
    iDay = DateDiff("d", dInterim1, sDate2)
    
    D = iDay
    m = iMonth Mod 12
    y = iMonth \ 12
    'YMDDif2 = CStr(Y) & " Years " & CStr(M) & " months " & CStr(D) & " days"
    YMDDif4 = CStr(y) & " س/" & CStr(m) & " ش/" & CStr(D) & " ي"

Exit Function
err_YMDDif4:

    If Err.Number = 94 Then
        'ignor, null
        Resume Next
    Else
        MsgBox Err.Number & vbCrLf & Err.Description
    End If
    
End Function

 

جعفر

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information