Option Explicit
Function isDayMonthReversed(strInDate As String) As Boolean
'' Excel reverses the date MDY order if it is not as per system date order
'' Objective: to check whether the date is reversed by Excel
Dim x As String
Dim y As String
Dim z As String
Dim strOutDate As String
Dim flag As Boolean
Dim resultB As Date
Dim dtSepr As String
Dim leadzero As Boolean
''find out the system date separator
dtSepr = Application.International(xlDateSeparator)
''has the system date with leading zero
leadzero = Application.International(xlDayLeadingZero)
If VBA.InStr(strInDate, dtSepr) > 0 Then
If VBA.IsDate(strInDate) Then
x = VBA.Split(strInDate, dtSepr)(0)
y = VBA.Split(strInDate, dtSepr)(1)
z = VBA.Split(strInDate, dtSepr)(2)
If leadzero Then
''add zero digit to the day and month
If Len(x) = 1 Then x = "0" & x
If Len(y) = 1 Then y = "0" & y
Else
''strip any zero digit from the day and month
If Len(x) = 2 Then x = Right$(x, 1)
If Len(y) = 2 Then y = Right$(y, 1)
End If
strInDate = x & dtSepr & y & dtSepr & z
resultB = DateValue(strInDate)
strOutDate = CStr(resultB)
If Not (strOutDate = strInDate) Then
flag = True
End If
End If
End If
isDayMonthReversed = flag
End Function
Sub test()
MsgBox isDayMonthReversed("02-13-2012")
End Sub
Function isDayMonthReversed(strInDate As String) As Boolean
'' Excel reverses the date MDY order if it is not as per system date order
'' Objective: to check whether the date is reversed by Excel
Dim x As String
Dim y As String
Dim z As String
Dim strOutDate As String
Dim flag As Boolean
Dim resultB As Date
Dim dtSepr As String
Dim leadzero As Boolean
''find out the system date separator
dtSepr = Application.International(xlDateSeparator)
''has the system date with leading zero
leadzero = Application.International(xlDayLeadingZero)
If VBA.InStr(strInDate, dtSepr) > 0 Then
If VBA.IsDate(strInDate) Then
x = VBA.Split(strInDate, dtSepr)(0)
y = VBA.Split(strInDate, dtSepr)(1)
z = VBA.Split(strInDate, dtSepr)(2)
If leadzero Then
''add zero digit to the day and month
If Len(x) = 1 Then x = "0" & x
If Len(y) = 1 Then y = "0" & y
Else
''strip any zero digit from the day and month
If Len(x) = 2 Then x = Right$(x, 1)
If Len(y) = 2 Then y = Right$(y, 1)
End If
strInDate = x & dtSepr & y & dtSepr & z
resultB = DateValue(strInDate)
strOutDate = CStr(resultB)
If Not (strOutDate = strInDate) Then
flag = True
End If
End If
End If
isDayMonthReversed = flag
End Function
Sub test()
MsgBox isDayMonthReversed("02-13-2012")
End Sub
No comments:
Post a Comment