I have a table in Access that contains a field which was setup as a 'Number' type field instead of a 'Date' type field and as a result, it displays the dates as 91205, 121409, etc. In trying to change the format of the dates so that it displays them as 9/12/2005, 12/14/2009, etc.,the module I had created in Access only converts some of the dates to the desired format. The dates that did manage to convert successfully were 5 digits, as none of the 6 digit dates converted. The query that calls the function is as follows: [codebox]SELECT QQQF_SPTRN0201.ST1ST & "-" & QQQF_SPTRN0201.ST2ST AS Expr1, QQQF_SPTRN0201.TRNCST, QQQF_SPTRN0201.TRNDST, NumToDate([TRNDST]) AS TrndstDate, QQQF_SPTRN0201.QTYST
FROM QQQF_SPTRN0201
WHERE (((QQQF_SPTRN0201.TRNCST)="D"))
ORDER BY QQQF_SPTRN0201.ST1ST;[/codebox]
The code that converts the field is as follows:
[codebox]Function NumToDate(lInput As Integer) As Date
Dim strTemp As String
strTemp = Format(lInput, "000000")
NumToDate = DateSerial(Val(Right(strTemp, 2)), Val(Left(strTemp, 2)), Val(Mid(strTemp, 3, 2)))
End Function[/codebox]
If there's a better way to do the date conversion, please let me know as I've even tried a different approach to the problem by trying to export the query results to Excel, but I'm not sure how to get it to work.
Any suggestions/ideas to this dilemma are welcomed.
Thanks!
Bookmarks