R
RB Smissaert
Have the following function to change an integer number in the form of
yyyymmdd to a date.
The return value has to be declared as a date.
Function ConvertDates(ByVal intDate As Long) As Date
'to return a date seems to be the only way to
'guarantee that the day and month are not reversed
'the problem is that null values will be converted
'to 12:00:00 AM, this can be dealt with by either
'changing to "" after or
'do ActiveWindow.DisplayZeros = False
'------------------------------------------------------------
If intDate = 0 Or intDate = Null Then
Exit Function
Else
ConvertDates = Right(intDate, 2) & "/" & _
Mid(intDate, 5, 2) & "/" & _
Left(intDate, 4)
End If
End Function
The problem arises when the variable intDate is a NULL value or EMPTY.
In that case the value that eventually appears in the sheet will be 12:00:00
AM
Now is there any way to avoid this other than changing the value afterwards
to ""
or doing ActiveWindow.DisplayZeros = False?
Both these methods have their drawbacks and I would like to handle this in
the function.
Thanks for any advice.
RBS
yyyymmdd to a date.
The return value has to be declared as a date.
Function ConvertDates(ByVal intDate As Long) As Date
'to return a date seems to be the only way to
'guarantee that the day and month are not reversed
'the problem is that null values will be converted
'to 12:00:00 AM, this can be dealt with by either
'changing to "" after or
'do ActiveWindow.DisplayZeros = False
'------------------------------------------------------------
If intDate = 0 Or intDate = Null Then
Exit Function
Else
ConvertDates = Right(intDate, 2) & "/" & _
Mid(intDate, 5, 2) & "/" & _
Left(intDate, 4)
End If
End Function
The problem arises when the variable intDate is a NULL value or EMPTY.
In that case the value that eventually appears in the sheet will be 12:00:00
AM
Now is there any way to avoid this other than changing the value afterwards
to ""
or doing ActiveWindow.DisplayZeros = False?
Both these methods have their drawbacks and I would like to handle this in
the function.
Thanks for any advice.
RBS