Sub dayName(dt As Long) As String
Dim dayNames() As String:dayNames = Array As String("","Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
Return dayNames(DateTime.GetDayOfWeek(dt))
End Sub
Sub monthName(dt As Long) As String
Dim monthNames() As String:monthNames = Array As String("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
Return monthNames(DateTime.GetMonth(dt))
End Sub
Sub ampmTime(dt As Long) As String
Dim h As Int
Dim i As Double
i = DateTime.GetMinute(dt)
h = DateTime.GetHour(dt)
If h <= 11 Then
If h = 0 Then h = 12 'coz we can't have hours as zero :)
Return h & ":" & NumberFormat(i, 2, 0) & "am"
End If
h = h - 12
If h = 0 Then h = 12 'coz we can't have hours as zero :)
Return h & ":" & NumberFormat(i, 2, 0) & "pm"
End Sub
Sub daySuffix(i As Int) As String 'add suffix to integer such as 10th 3rd 1st 2022nd etc.
Dim s As String
Dim j As Int
s = i 'change the int to a string
j = i 'make a copy of i that we can chop up
If s.Length > 2 Then s = s.SubString(s.Length - 2)
j = s 'j is now a number that is no bigger than 2 digits
If j >= 4 AND j <= 20 Then Return i & "th" 'these last few
If s.EndsWith("1") Then Return i & "st" 'lines work out
If s.EndsWith("2") Then Return i & "nd" 'the correct suffix
If s.EndsWith("3") Then Return i & "rd" 'and send back the
Return i & "th" 'original number as a string with the correct suffix after it.
End Sub
Sub longDate(dt As Long) As String
Return dayName(dt) & " " & daySuffix(DateTime.GetDayOfMonth(dt)) & " of " & monthName(dt) & ", " & DateTime.GetYear(dt)
End Sub
Sub ampmTimeAndlongDate(dt As Long) As String
Return ampmTime(dt) & " on " & longDate(dt)
End Sub