Thursday, January 8, 2015

Modify Date_Change Date_Calculated Date


'###############################################################################
'Name: Calculate_Date
'Created[By] : msrivastava
'@Description Purpose: This function is used to add to or remove days from a given [dtDate] and return
'new date, in the correct format.
' @Documentation Parameters:  <dtDate>-  Date to be modified.
'<intDay>- number of days to be added/subtracted by. use (-)negative to subtract.
'###############################################################################
Public Function Calculate_Date(dtDate, intDay)
Dim NewDate, chkDate, val, DateFormat, FormatDate

Reporter.ReportEvent micInfo, "Calculate Date", "Add ["& intDay& "] days to a given ["& dtDate& "] and return New Date."
on error resume next
val = DataTable("DateFormat", dtGlobalSheet)
If err.number <> 0 Then
DateFormat = "en-US"
else
DateFormat = DataTable("DateFormat", dtGlobalSheet)
End If

If instr(1, DateFormat, "GB") > 1 Then
NewDate = ConvertDate(dtDate)
End If

NewDate = DateAdd("d", intDay, dtDate)
chkDate = Weekday(NewDate)
Select Case chkDate
Case 1
NewDate = DateAdd("d", intDay+ 1, dtDate)

Case 7
NewDate = DateAdd("d", intDay+ 2, dtDate)
End Select
 
'once weekday is set, format to the based on business unit.
'GetDate(inDate, fmt)
    FormatDate = GetDate(NewDate, DateFormat)

'Return reformatted date
Calculate_Date = FormatDate
End Function

No comments: