[RESOLVED] DateDiff Month
Is there a way to make datediff for months show a decimal number? I need to find out partial dates.
The user will enter a value such as 4/1 (mm/dd) and 12/5(mm/dd) and I need to find out the monthly value between it.
I was thinking of counting the days and dividing by 30..but that wouldn't be very pretty.
also weeks wouldnt work very well as sometimes theyre only partial weeks..
Re: [RESOLVED] DateDiff Month
Somthing like this. Fraction of a month isn't hard, but what I did was subtract the fraction of the first month, and added the fraction of the second month. Not sure if that's right, though.
VB Code:
Option Explicit
Private Sub Form_Load()
Dim s As Date, t As Integer, u As Long, v As Long
Dim u1 As Long, v1 As Long
' 2 months
t = DateDiff("m", Now, DateSerial(5, 10, 5)) ' months
' u = days part
' v = days in month
u = CDbl(DateDiff("d", DateSerial(Year(Now), Month(Now), 1), Now))
v = CDbl(Day(DateSerial(Year(Now), Month(Now) + 1, 0)))
u1 = CDbl(10) ' second date days
v1 = CDbl(Day(DateSerial(5, 10 + 1, 0)))
' 2 - 17/31 + 10/31 = 1.77 months
MsgBox Format(t - (u / v) + (u1 / v1), "0.##")
End Sub
Re: [RESOLVED] DateDiff Month
When dealing with salary you can calculate the daily salary, and calulating days worked is easy, so why would you want to do anything but what I previously suggested?
Re: [RESOLVED] DateDiff Month
Quote:
Originally Posted by MartinLiss
When dealing with salary you can calculate the daily salary, and calulating days worked is easy, so why would you want to do anything but what I previously suggested?
Because I am not just calculating their work days. I have to do several different calculations for which department they would be in, or what % they have allocated to each program.