The sFormat Date Function

This function formats a date according to the Windows Regional Settings, using a four-digit year, and optionally including a time string in the result:

Function sFormatDate(dDate As Date, Optional bTimeReq) As String

Dim sDate As String

'Default bTimeReq to False if not supplied If IsMissing(bTimeReq) Then bTimeReq = False

Select Case Application.International(xlDateOrder) Case 0 'month-day-year sDate = Format$(dDate, "mm/dd/yyyy") Case 1 'day-month-year sDate = Format$(dDate, "dd/mm/yyyy") Case 2 'year-month-day sDate = Format$(dDate, "yyyy/mm/dd")

End Select

If bTimeReq Then sDate = sDate & " " & Format$(dDate, "hh:mm:ss") sFormatDate = sDate End Function dDate is the Excel date number, and bTimeReq is an optional argument that should be set to True to include the time string in the result.

0 0

Post a comment