-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDateFunctions.bas
More file actions
66 lines (65 loc) · 1.92 KB
/
DateFunctions.bas
File metadata and controls
66 lines (65 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Attribute VB_Name = "DateFunctions"
'Sonya - Date Functions
Function getEarliestDate(ByVal sheetname As String, ByVal rangeAsString As String) As Date
Dim rng As Range
Set rng = Worksheets(sheetname).Range(rangeAsString)
Dim cell As Range
Dim result As Date
result = CDate(rng(1).Value)
For Each cell In rng
If CDate(cell.Value) < result Then
result = CDate(cell.Value)
End If
Next cell
getEarliestDate = result
End Function
Function getLatestDate(ByVal sheetname As String, ByVal rangeAsString As String) As Date
Dim rng As Range
Set rng = Worksheets(sheetname).Range(rangeAsString)
Dim cell As Range
Dim result As Date
result = CDate(rng(1).Value)
For Each cell In rng
If CDate(cell.Value) > result Then
result = CDate(cell.Value)
End If
Next cell
getLatestDate = result
End Function
Function getDayWithSuffix(ByVal d As Date) As String
Dim dayStr As String
dayStr = day(d)
Dim found As Boolean
found = False
If CInt(dayStr) = "11" Or CInt(dayStr) = "12" Or CInt(dayStr) = "13" Then
dayStr = dayStr & "th"
found = True
Else
Dim number As String
number = Mid(dayStr, Len(dayStr), 1)
If number = "1" Then
dayStr = dayStr & "st"
found = True
Else
If number = "2" Then
dayStr = dayStr & "nd"
found = True
Else
If number = "3" Then
dayStr = dayStr & "rd"
found = True
End If
End If
End If
End If
If found = False Then
dayStr = dayStr & "th"
End If
getDayWithSuffix = dayStr
End Function
Function addZeroToHrOrMin(ByVal hourOrMin As Integer) As String
addZeroToHrOrMin = hourOrMin
If hourOrMin < 10 Then
addZeroToHrOrMin = "0" & hourOrMin
End If
End Function