| | |
|
|
|
Convert Date |
| message from =?Utf-8?B?U2Ft?= on 3 Jun 2004 |
Hi,
I have a date (i.e. 970401 = 1st April 1997 - UK) how could I convert this to a date? Is there a function that would do this for me?
And where’s the Knowledge Base on Microsoft’s site gone?
Many thanks
Sam
|
| Douglas J. Steele replied to John Vinson on 3 Jun 2004 |
this to a date? Is there a function that would do this for me?
Since the OP is from the UK, and probably has his Short Date format as
dd/mm/yyyy, the following is probably safer:
Function ConvertTextToDate(txtdate As Variant) As Variant
Dim intDay As Integer
Dim intMonth As Integer
Dim intYear As Integer
If IsNull(txtdate) = False Then
intDay = CInt(Right(txtdate, 2)
intMonth = CInt(Mid(txtdate, 3, 2))
intYear = CInt(Left(txtdate, 2))
If intYear > 50 Then
intYear = intYear + 1900
Else
intYear = intYear + 2000
End If
ConvertTextToDate = DateSerial(intYear, intMonth, intDay)
Else
ConvertTextToDate = Null
End If
End Function
(You may want to play with the 50, depending on what the input data actually
looks like)
|
|
Archived message: Convert Date (Microsoft Access Database)