This function Changes the format of the date to a requested format. It will change the given date into following format:
1). "mm/dd/yy"
2). "mm/dd/yyyy"
3). “weekday,Month day,year"
4). "yy/mm/dd"
5). “dd/mm/yy______________________________________________________________________________________
'Example : Format_Date "01/26/1992",1
'frmtType = 1 for "mm/dd/yy"
'frmtType = 2 for "mm/dd/yyyy"
'frmtType = 3 for "weekday,Month day,year"
'frmtType = 4 for "yy/mm/dd"
'frmtType = 5 for "dd/mm/yy"
'*******************************************************************************************************************
'*******************************************************************************************************************
Function Format_Date(aDate,frmtType)
Dim Curr_Day,Curr_Mon,Curr_Year,To_Date
Curr_Day = datepart("d", aDate)
Curr_Mon = datepart("m", aDate)
Curr_Year = datepart("yyyy", aDate)
If frmtType=1 then
Curr_Year = Right(Curr_year,2)
If Len(Curr_Day) = 1 Then
Curr_Day = "0" & Curr_Day
End If
If Len(Curr_Mon) = 1 Then
Curr_Mon = "0" & Curr_Mon
End If
To_Date = Curr_Mon & "/" & Curr_Day & "/" & Curr_Year
Format_Date = To_Date
End If
If frmtType = 2 Then
If Len(Curr_Day) = 1 Then
Curr_Day = "0" & Curr_Day
End If
If Len(Curr_Mon) = 1 Then
Curr_Mon = "0" & Curr_Mon
End If
To_Date = Curr_Mon & "/" & Curr_Day & "/" & Curr_Year
Format_Date = To_Date
End If
If frmtType= 3 Then
To_Date = Formatdatetime(aDate,1)
Format_Date = To_Date
End If
If frmtType = 4 Then
Curr_Year = Right(Curr_year,2)
If Len(Curr_Day) = 1 Then
Curr_Day = "0" & Curr_Day
End If
If Len(Curr_Mon) = 1 Then
Curr_Mon = "0" & Curr_Mon
End If
To_Date = Curr_Year & "/" & Curr_Mon & "/" & Curr_Day
Format_Date = To_Date
End If
If frmtType = 5 Then
Curr_Year = Right(Curr_year,2)
If Len(Curr_Day) = 1 Then
Curr_Day = "0" & Curr_Day
End If
If Len(Curr_Mon) = 1 Then
Curr_Mon = "0" & Curr_Mon
End If
To_Date = Curr_Day & "/" & Curr_Mon & "/" & Curr_Year
Format_Date = To_Date
End If
End Function
'*******************************************************************************************************************
'*******************************************************************************************************************
No comments:
Post a Comment