Hi,
Whatever case maybe you can try the following:
If you want to convert a date into DD/MM/YYYY format:
Public Function DDMMYYYY(byVal MyDate)
'This Function Takes Any Valid Date And Returns DD/MM/YYYY
Dim MyDay
Dim MyMonth
Dim MyYear
Dim MyDay2
Dim month2
If IsDate(MyDate) Then
MyDay = Day(MyDate): MyMonth = Month(MyDate): MyYear = Year(MyDate)
If Len(MyDay) = 1 Then
MyDay2 = "0" + CStr(MyDay)
Else
MyDay2 = CStr(MyDay)
End If
If Len(MyMonth) = 1 Then
month2 = "0" + CStr(MyMonth)
Else
month2 = CStr(MyMonth)
End If
DDMMYYYY = MyDay2 + "/" + month2 + "/" + CStr(MyYear)
End If
End Function
If you want to convert a date into MM/DD/YY format:
Public Function MMDDYY(ByVal MyDate)
'This Function Takes DD/MM/YYYY And Returns MM/DD/YY
Dim MyDay
Dim MyMonth
Dim MyYear
Dim length
Dim position1 As Integer
Dim position2 As Integer
If IsDate(MyDate) Then
length = Len(MyDate)
position1 = InStr(CInt(1), MyDate, "/")
position2 = InStr(position1 + 1, MyDate, "/")
MyDay = Left(MyDate, position1 - 1)
MyMonth = Mid(MyDate, position1 + 1, (position2 - position1 - 1))
MyYear = Right(MyDate, 2)
MMDDYY = MyMonth + "/" + MyDay + "/" + MyYear
End If
End Function
Hope this helps,
Lalit
Life Means More...;)
|