vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="VB6Parse Library Reference - day - Datetime">
    <title>day - Datetime - VB6Parse Library Reference</title>
    <link rel="stylesheet" href="../../../assets/css/style.css">
    <link rel="stylesheet" href="../../../assets/css/docs-style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
    <script src="../../../assets/js/theme-switcher.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/vbnet.min.js"></script>
    <script>hljs.highlightAll();</script>
</head>
<body>
    <header class="docs-header">
        <div class="container">
            <h1><a href="../../../index.html">VB6Parse</a> / <a href="../../../library/index.html">Library</a> / <a href="../../../library/functions/datetime/index.html">Datetime</a> / day</h1>
            <p class="tagline">VB6 Library Reference</p>
        </div>
    </header>

    <nav class="docs-nav">
        <div class="container">
            <a href="../../../index.html">Home</a>
            <a href="../../../library/index.html">Library Reference</a>
            <a href="../../../documentation.html">Documentation</a>
            <a href="https://docs.rs/vb6parse" target="_blank">API Docs</a>
            <a href="https://github.com/scriptandcompile/vb6parse" target="_blank">GitHub</a>
            <button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
                <span class="theme-icon">🌙</span>
            </button>
        </div>
    </nav>

    <main class="container">
        
        <article class="library-item">
            <h1 id="day-function">Day Function</h1>
<p>Returns a whole number between 1 and 31, inclusive, representing the day of the month.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">Day(date)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><strong>date</strong>: Required. Any Variant, numeric expression, string expression, or any combination
  that can represent a date. If date contains Null, Null is returned.</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns an Integer representing the day of the month (1-31). Returns Null if the date
parameter contains Null.</p>
<h2 id="remarks">Remarks</h2>
<p>The <code>Day</code> function extracts the day component from a date value. It's one of the primary
date component extraction functions in VB6, along with <code>Year</code>, <code>Month</code>, <code>Weekday</code>, <code>Hour</code>,
<code>Minute</code>, and <code>Second</code>.
<strong>Important Characteristics:</strong>
- Returns values 1-31 depending on the month
- Works with Date variables, date literals, and date expressions
- Returns Null if input is Null (Variant behavior)
- Automatically handles different month lengths
- Time portion of datetime values is ignored
- Type mismatch error if argument cannot be interpreted as date
- Can be used with date arithmetic results</p>
<h2 id="examples">Examples</h2>
<h3 id="basic-usage">Basic Usage</h3>
<pre><code class="language-vbnet">&#x27; Extract day from date literal
Dim d As Integer
d = Day(#1/15/2025#)  &#x27; Returns 15
&#x27; From Date variable
Dim birthday As Date
birthday = #5/23/1990#
d = Day(birthday)  &#x27; Returns 23
&#x27; From current date
d = Day(Date)  &#x27; Returns current day</code></pre>
<h3 id="with-date-functions">With Date Functions</h3>
<pre><code class="language-vbnet">&#x27; Extract day from DateSerial result
Dim constructedDate As Date
constructedDate = DateSerial(2025, 12, 25)
Dim dayNum As Integer
dayNum = Day(constructedDate)  &#x27; Returns 25
&#x27; From DateAdd calculation
Dim futureDate As Date
futureDate = DateAdd(&quot;d&quot;, 10, Date)
dayNum = Day(futureDate)</code></pre>
<h3 id="date-validation">Date Validation</h3>
<pre><code class="language-vbnet">Function IsLastDayOfMonth(dateValue As Date) As Boolean
    Dim nextDay As Date
    nextDay = DateAdd(&quot;d&quot;, 1, dateValue)
    IsLastDayOfMonth = (Day(nextDay) = 1)
End Function
&#x27; Alternative using month comparison
Function IsLastDayOfMonth2(dateValue As Date) As Boolean
    IsLastDayOfMonth2 = (Day(dateValue + 1) = 1)
End Function</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<h3 id="get-days-in-month">Get Days in Month</h3>
<pre><code class="language-vbnet">Function DaysInMonth(dateValue As Date) As Integer
    &#x27; Get last day of the month
    Dim firstOfNextMonth As Date
    firstOfNextMonth = DateSerial(Year(dateValue), Month(dateValue) + 1, 1)
    DaysInMonth = Day(firstOfNextMonth - 1)
End Function
&#x27; Alternative approach
Function DaysInMonth2(yr As Integer, mo As Integer) As Integer
    DaysInMonth2 = Day(DateSerial(yr, mo + 1, 0))
End Function</code></pre>
<h3 id="extract-date-components">Extract Date Components</h3>
<pre><code class="language-vbnet">Sub DisplayDateParts(dateValue As Date)
    Dim yr As Integer, mo As Integer, dy As Integer
    yr = Year(dateValue)
    mo = Month(dateValue)
    dy = Day(dateValue)
    MsgBox &quot;Year: &quot; &amp; yr &amp; &quot;, Month: &quot; &amp; mo &amp; &quot;, Day: &quot; &amp; dy
End Sub</code></pre>
<h3 id="day-based-filtering">Day-Based Filtering</h3>
<pre><code class="language-vbnet">Function IsFirstHalfOfMonth(dateValue As Date) As Boolean
    IsFirstHalfOfMonth = (Day(dateValue) &lt;= 15)
End Function
Function IsSecondHalfOfMonth(dateValue As Date) As Boolean
    IsSecondHalfOfMonth = (Day(dateValue) &gt; 15)
End Function
Function IsMonthStart(dateValue As Date) As Boolean
    IsMonthStart = (Day(dateValue) = 1)
End Function</code></pre>
<h3 id="date-comparison-by-day">Date Comparison by Day</h3>
<pre><code class="language-vbnet">Function SameDayOfMonth(date1 As Date, date2 As Date) As Boolean
    SameDayOfMonth = (Day(date1) = Day(date2))
End Function
Function CompareDays(date1 As Date, date2 As Date) As Integer
    &#x27; Returns: -1 if date1&#x27;s day &lt; date2&#x27;s day
    &#x27;           0 if same day
    &#x27;           1 if date1&#x27;s day &gt; date2&#x27;s day
    Dim d1 As Integer, d2 As Integer
    d1 = Day(date1)
    d2 = Day(date2)
    If d1 &lt; d2 Then
        CompareDays = -1
    ElseIf d1 &gt; d2 Then
        CompareDays = 1
    Else
        CompareDays = 0
    End If
End Function</code></pre>
<h3 id="reconstruct-date-with-modified-day">Reconstruct Date with Modified Day</h3>
<pre><code class="language-vbnet">Function ChangeDay(originalDate As Date, newDay As Integer) As Date
    &#x27; Create new date with same year/month but different day
    ChangeDay = DateSerial(Year(originalDate), Month(originalDate), newDay)
End Function
&#x27; Move to specific day of current month
Function MoveToDayOfMonth(dayNum As Integer) As Date
    MoveToDayOfMonth = DateSerial(Year(Date), Month(Date), dayNum)
End Function</code></pre>
<h3 id="loop-through-days-of-month">Loop Through Days of Month</h3>
<pre><code class="language-vbnet">Sub ProcessAllDaysInMonth(yr As Integer, mo As Integer)
    Dim dayCount As Integer
    Dim currentDay As Date
    Dim i As Integer
    dayCount = Day(DateSerial(yr, mo + 1, 0))
    For i = 1 To dayCount
        currentDay = DateSerial(yr, mo, i)
        Debug.Print &quot;Day &quot; &amp; Day(currentDay) &amp; &quot;: &quot; &amp; Format(currentDay, &quot;dddd&quot;)
    Next i
End Sub</code></pre>
<h3 id="pay-period-calculations">Pay Period Calculations</h3>
<pre><code class="language-vbnet">Function GetPayPeriod(dateValue As Date) As String
    &#x27; Bi-monthly pay periods: 1-15 and 16-end
    If Day(dateValue) &lt;= 15 Then
        GetPayPeriod = &quot;First Half&quot;
    Else
        GetPayPeriod = &quot;Second Half&quot;
    End If
End Function
Function IsPayday(dateValue As Date) As Boolean
    Dim dy As Integer
    dy = Day(dateValue)
    &#x27; Payday on 15th and last day of month
    IsPayday = (dy = 15) Or (Day(dateValue + 1) = 1)
End Function</code></pre>
<h3 id="birthdayanniversary-checks">Birthday/Anniversary Checks</h3>
<pre><code class="language-vbnet">Function IsBirthdayMonth(birthday As Date) As Boolean
    &#x27; Check if current month/day matches birthday
    IsBirthdayMonth = (Month(Date) = Month(birthday)) And _
                      (Day(Date) = Day(birthday))
End Function
Function DaysUntilBirthday(birthday As Date) As Integer
    Dim thisYearBirthday As Date
    thisYearBirthday = DateSerial(Year(Date), Month(birthday), Day(birthday))
    If thisYearBirthday &lt; Date Then
        &#x27; Birthday already passed this year
        thisYearBirthday = DateSerial(Year(Date) + 1, Month(birthday), Day(birthday))
    End If
    DaysUntilBirthday = DateDiff(&quot;d&quot;, Date, thisYearBirthday)
End Function</code></pre>
<h3 id="data-grouping-by-day">Data Grouping by Day</h3>
<pre><code class="language-vbnet">Function GetDayGroup(dateValue As Date) As String
    Dim dy As Integer
    dy = Day(dateValue)
    Select Case dy
        Case 1 To 10
            GetDayGroup = &quot;Days 1-10&quot;
        Case 11 To 20
            GetDayGroup = &quot;Days 11-20&quot;
        Case Else
            GetDayGroup = &quot;Days 21-31&quot;
    End Select
End Function</code></pre>
<h2 id="advanced-usage">Advanced Usage</h2>
<h3 id="calendar-grid-generator">Calendar Grid Generator</h3>
<pre><code class="language-vbnet">Sub GenerateMonthCalendar(yr As Integer, mo As Integer)
    Dim firstDay As Date
    Dim lastDay As Date
    Dim currentDate As Date
    Dim dayOfWeek As Integer
    Dim daysInMonth As Integer
    firstDay = DateSerial(yr, mo, 1)
    daysInMonth = Day(DateSerial(yr, mo + 1, 0))
    &#x27; Print header
    Debug.Print &quot;Sun Mon Tue Wed Thu Fri Sat&quot;
    &#x27; Print leading spaces
    dayOfWeek = Weekday(firstDay, vbSunday)
    Debug.Print String((dayOfWeek - 1) * 4, &quot; &quot;);
    &#x27; Print days
    For i = 1 To daysInMonth
        currentDate = DateSerial(yr, mo, i)
        Debug.Print Format(Day(currentDate), &quot;000&quot;) &amp; &quot; &quot;;
        If Weekday(currentDate, vbSunday) = 7 Then
            Debug.Print  &#x27; New line
        End If
    Next i
End Sub</code></pre>
<h3 id="date-range-iterator">Date Range Iterator</h3>
<pre><code class="language-vbnet">Function GetDateRange(startDate As Date, endDate As Date) As Variant
    &#x27; Returns array of dates in range
    Dim dayCount As Long
    Dim dates() As Date
    Dim i As Long
    dayCount = DateDiff(&quot;d&quot;, startDate, endDate) + 1
    ReDim dates(0 To dayCount - 1)
    For i = 0 To dayCount - 1
        dates(i) = DateAdd(&quot;d&quot;, i, startDate)
        Debug.Print &quot;Day &quot; &amp; Day(dates(i)) &amp; &quot;: &quot; &amp; dates(i)
    Next i
    GetDateRange = dates
End Function</code></pre>
<h3 id="billing-cycle-calculator">Billing Cycle Calculator</h3>
<pre><code class="language-vbnet">Function CalculateBillingDay(startDate As Date, monthsElapsed As Integer) As Date
    &#x27; Keep same day-of-month for billing cycle
    Dim billingDay As Integer
    billingDay = Day(startDate)
    CalculateBillingDay = DateSerial( _
        Year(DateAdd(&quot;m&quot;, monthsElapsed, startDate)), _
        Month(DateAdd(&quot;m&quot;, monthsElapsed, startDate)), _
        billingDay)
End Function
Function AdjustForMonthEnd(targetDate As Date, originalDay As Integer) As Date
    &#x27; Handle when original day doesn&#x27;t exist in target month
    Dim targetMonth As Date
    Dim maxDayInMonth As Integer
    targetMonth = DateSerial(Year(targetDate), Month(targetDate), 1)
    maxDayInMonth = Day(DateSerial(Year(targetDate), Month(targetDate) + 1, 0))
    If originalDay &gt; maxDayInMonth Then
        AdjustForMonthEnd = DateSerial(Year(targetDate), Month(targetDate), maxDayInMonth)
    Else
        AdjustForMonthEnd = DateSerial(Year(targetDate), Month(targetDate), originalDay)
    End If
End Function</code></pre>
<h3 id="date-pattern-analyzer">Date Pattern Analyzer</h3>
<pre><code class="language-vbnet">Function AnalyzeDatePattern(dates() As Date) As String
    &#x27; Determine if dates follow a pattern
    Dim i As Long
    Dim allSameDay As Boolean
    Dim firstDay As Integer
    If UBound(dates) &lt; LBound(dates) Then
        AnalyzeDatePattern = &quot;Empty&quot;
        Exit Function
    End If
    firstDay = Day(dates(LBound(dates)))
    allSameDay = True
    For i = LBound(dates) + 1 To UBound(dates)
        If Day(dates(i)) &lt;&gt; firstDay Then
            allSameDay = False
            Exit For
        End If
    Next i
    If allSameDay Then
        AnalyzeDatePattern = &quot;Monthly on day &quot; &amp; firstDay
    Else
        AnalyzeDatePattern = &quot;Variable days&quot;
    End If
End Function</code></pre>
<h3 id="work-schedule-helper">Work Schedule Helper</h3>
<pre><code class="language-vbnet">Function IsWorkDay(dateValue As Date, workDays As String) As Boolean
    &#x27; workDays: comma-separated list like &quot;1,15,30&quot;
    Dim dayList() As String
    Dim i As Integer
    Dim currentDay As Integer
    currentDay = Day(dateValue)
    dayList = Split(workDays, &quot;,&quot;)
    For i = LBound(dayList) To UBound(dayList)
        If CInt(Trim(dayList(i))) = currentDay Then
            IsWorkDay = True
            Exit Function
        End If
    Next i
    IsWorkDay = False
End Function</code></pre>
<h3 id="leap-year-day-check">Leap Year Day Check</h3>
<pre><code class="language-vbnet">Function IsLeapYearDay(dateValue As Date) As Boolean
    &#x27; Check if date is February 29
    IsLeapYearDay = (Month(dateValue) = 2) And (Day(dateValue) = 29)
End Function
Function HasLeapYearDayBetween(startDate As Date, endDate As Date) As Boolean
    Dim yr As Integer
    Dim leapDay As Date
    For yr = Year(startDate) To Year(endDate)
        On Error Resume Next
        leapDay = DateSerial(yr, 2, 29)
        If Err.Number = 0 Then
            If leapDay &gt;= startDate And leapDay &lt;= endDate Then
                HasLeapYearDayBetween = True
                Exit Function
            End If
        End If
        Err.Clear
    Next yr
    HasLeapYearDayBetween = False
End Function</code></pre>
<h3 id="database-query-builder">Database Query Builder</h3>
<pre><code class="language-vbnet">Function BuildDayFilter(targetDay As Integer) As String
    &#x27; Build SQL WHERE clause for specific day of month
    BuildDayFilter = &quot;Day(DateField) = &quot; &amp; targetDay
End Function
Function GetRecordsForDayRange(startDay As Integer, endDay As Integer) As String
    GetRecordsForDayRange = &quot;Day(DateField) BETWEEN &quot; &amp; startDay &amp; &quot; AND &quot; &amp; endDay
End Function</code></pre>
<h2 id="error-handling">Error Handling</h2>
<pre><code class="language-vbnet">Function SafeDay(dateValue As Variant) As Variant
    On Error GoTo ErrorHandler
    If IsNull(dateValue) Then
        SafeDay = Null
        Exit Function
    End If
    If Not IsDate(dateValue) Then
        SafeDay = Null
        Exit Function
    End If
    SafeDay = Day(dateValue)
    Exit Function
ErrorHandler:
    SafeDay = Null
End Function</code></pre>
<h3 id="common-errors">Common Errors</h3>
<ul>
<li><strong>Error 13</strong> (Type mismatch): Argument is not a valid date</li>
<li><strong>Error 94</strong> (Invalid use of Null): Using Null date without handling</li>
</ul>
<h2 id="performance-considerations">Performance Considerations</h2>
<ul>
<li><code>Day</code> is a fast, direct component extraction</li>
<li>More efficient than string parsing with <code>Format</code></li>
<li>No performance difference between extracting from Date vs Variant</li>
<li>Cache results when using repeatedly on same date</li>
<li>Combine with <code>Year</code> and <code>Month</code> for full date decomposition</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<h3 id="use-for-component-extraction">Use for Component Extraction</h3>
<pre><code class="language-vbnet">&#x27; Good - Direct component access
dayNum = Day(someDate)
&#x27; Avoid - String manipulation overhead
dayNum = CInt(Format(someDate, &quot;dd&quot;))</code></pre>
<h3 id="validate-date-before-extraction">Validate Date Before Extraction</h3>
<pre><code class="language-vbnet">&#x27; Good - Check for valid date
If IsDate(userInput) Then
    dayNum = Day(CDate(userInput))
End If
&#x27; Avoid - May cause type mismatch error
dayNum = Day(userInput)</code></pre>
<h3 id="handle-null-values-in-variants">Handle Null Values in Variants</h3>
<pre><code class="language-vbnet">&#x27; Good - Check for Null
If Not IsNull(dateVariant) Then
    dayNum = Day(dateVariant)
End If
&#x27; Avoid - May propagate Null unexpectedly
dayNum = Day(dateVariant)</code></pre>
<h3 id="combine-with-dateserial-for-date-manipulation">Combine with <code>DateSerial</code> for Date Manipulation</h3>
<pre><code class="language-vbnet">&#x27; Good - Reconstruct date with modified component
newDate = DateSerial(Year(oldDate), Month(oldDate), 15)
&#x27; Good - Get last day of month
lastDay = Day(DateSerial(yr, mo + 1, 0))</code></pre>
<h2 id="comparison-with-other-functions">Comparison with Other Functions</h2>
<h3 id="day-vs-format"><code>Day</code> vs <code>Format</code></h3>
<pre><code class="language-vbnet">&#x27; Day - Returns integer, fast
dayNum = Day(someDate)  &#x27; Returns 15
&#x27; Format - Returns string, slower, more flexible
dayStr = Format(someDate, &quot;dd&quot;)  &#x27; Returns &quot;15&quot;
dayStr = Format(someDate, &quot;d&quot;)   &#x27; Returns &quot;15&quot; (no leading zero)</code></pre>
<h3 id="day-vs-datepart"><code>Day</code> vs <code>DatePart</code></h3>
<pre><code class="language-vbnet">&#x27; Day - Specific function for day of month
dayNum = Day(someDate)
&#x27; DatePart - Generic function, can extract any part
dayNum = DatePart(&quot;d&quot;, someDate)  &#x27; Same result</code></pre>
<h3 id="day-vs-weekday"><code>Day</code> vs <code>Weekday</code></h3>
<pre><code class="language-vbnet">&#x27; Day - Day of month (1-31)
dayOfMonth = Day(#1/15/2025#)  &#x27; Returns 15
&#x27; Weekday - Day of week (1-7)
dayOfWeek = Weekday(#1/15/2025#)  &#x27; Returns 4 (Wednesday)</code></pre>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Only returns day of month, not day of year or week</li>
<li>Returns <code>Null</code> for <code>Null</code> input (<code>Variant</code> propagation)</li>
<li>No built-in validation of day validity for given month</li>
<li>Does not indicate if day is weekend, holiday, etc.</li>
<li>Cannot distinguish between different months with same day</li>
</ul>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><code>Year</code>: Extracts year component from date</li>
<li><code>Month</code>: Extracts month component from date</li>
<li><code>Weekday</code>: Returns day of week (1-7)</li>
<li><code>DatePart</code>: Generic date part extraction</li>
<li><code>DateSerial</code>: Constructs date from components</li>
<li><code>Format</code>: Formats date as string with custom patterns</li>
<li><code>Hour</code>, <code>Minute</code>, <code>Second</code>: Extract time components</li>
</ul>
        </article>
        
        <div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
            <p>
                <a href="index.html">← Back to Datetime</a> |
                <a href="../index.html">View all functions</a>
            </p>
        </div>

    </main>

    <footer>
        <div class="container">
            <p>&copy; 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
        </div>
    </footer>
</body>
</html>