vb Human Date

Function HumanDate(dDate)
	If IsDate(dDate) Then
		'returns the date in a user friendly format, e.g. Tuesday 26th January 2010, 21:45pm
		Dim dYear
		Dim dMonth
		Dim dMonthName
		Dim dDay
		Dim dDayName
		Dim dDaySuffix
		Dim dTime
		Dim dTimeSuffix
		Dim dReturn

		dYear = DatePart("yyyy",dDate)
		dMonth = DatePart("m",dDate)
		dMonthName = MonthName(dMonth)
		dDay = DatePart("d",dDate)
		dDayName = weekdayname(weekday(dDate))

		Select Case dDay
			Case 1,21,31
				dDaySuffix = "st"
			Case 2,22
				dDaySuffix = "nd"
			Case 3,23
				dDaySuffix = "rd"
			Case 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,24,25,26,27,28,29,30
				dDaySuffix = "th"
		End Select
		
		dTime = FormatDateTime(Now(),4)

		If DatePart("h",dDate) >= 12 Then
			dTimeSuffix = "pm"
		Else
			dTimeSuffix = "am"
		End If

		dReturn = dDayName & " " & dDay & dDaySuffix & " " & dMonthName & " " & dYear & ", " & dTime & dTimeSuffix
		
		HumanDate = dReturn
	Else
		HumanDate = dDate
	End If
End Function
Formats a date to a human readable/friendly format.

Updated: Saturday 9th October 2010, 13:29pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.