Tuesday, March 30, 2010

Subtract the given no.of days from today

There might be some instances where you would require to subtract the give number of days from today.... so here is the solution.

No need to worry about the month rollback or year rollback... excel would take care of this automatically

Function Subtract_Date_from_Today(ByRef noofdays As Integer)
    result = Now() - noofdays
    Dt = Day(result)
    Mo = Month(result)
    Yr = Right(Year(result), 2)
    If Len(Mo) = 1 Then Mo = "0" & Mo
    If Len(Dt) = 1 Then Dt = "0" & Dt
    Subtract_Date_from_Today = Mo & Dt & Yr
End Function

No comments:

Post a Comment