Repository navigation
Expand file tree
/
Copy pathDateAndTime.xml
More file actions
1798 lines (1511 loc) · 121 KB
/
Copy pathDateAndTime.xml
File metadata and controls
1798 lines (1511 loc) · 121 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
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<Type Name="DateAndTime" FullName="Microsoft.VisualBasic.DateAndTime">
<TypeSignature Language="C#" Value="public sealed class DateAndTime" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit DateAndTime extends System.Object" />
<TypeSignature Language="DocId" Value="T:Microsoft.VisualBasic.DateAndTime" />
<TypeSignature Language="VB.NET" Value="Public Module DateAndTime" />
<TypeSignature Language="C++ CLI" Value="public ref class DateAndTime sealed" />
<TypeSignature Language="F#" Value="type DateAndTime = class" />
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8">
<AttributeName>Microsoft.VisualBasic.CompilerServices.StandardModule</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>The <see langword="DateAndTime" /> module contains the procedures and properties used in date and time operations.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This module supports the Visual Basic language keywords and run-time library members that get the current date or time, perform date calculations, return a date or time, set the date or time, or time the duration of a process.
## Examples
This example uses the `Today` property to return the current system date.
```vb
Dim thisDate As Date
thisDate = Today
```
]]></format>
</remarks>
<related type="Article" href="~/docs/visual-basic/language-reference/keywords/dates-and-times-summary.md">Dates and Times Summary</related>
<related type="Article" href="~/docs/visual-basic/language-reference/keywords/index.md">Keywords (Visual Basic)</related>
<related type="Article" href="~/docs/visual-basic/language-reference/runtime-library-members.md">Visual Basic Run-Time Library Members</related>
</Docs>
<Members>
<MemberGroup MemberName="DateAdd">
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Returns a <see langword="Date" /> value containing a date and time value to which a specified time interval has been added.</summary>
</Docs>
</MemberGroup>
<Member MemberName="DateAdd">
<MemberSignature Language="C#" Value="public static DateTime DateAdd (Microsoft.VisualBasic.DateInterval Interval, double Number, DateTime DateValue);" />
<MemberSignature Language="ILAsm" Value=".method public static valuetype System.DateTime DateAdd(valuetype Microsoft.VisualBasic.DateInterval Interval, float64 Number, valuetype System.DateTime DateValue) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.DateAdd(Microsoft.VisualBasic.DateInterval,System.Double,System.DateTime)" />
<MemberSignature Language="VB.NET" Value="Public Function DateAdd (Interval As DateInterval, Number As Double, DateValue As DateTime) As DateTime" />
<MemberSignature Language="C++ CLI" Value="public:
 static DateTime DateAdd(Microsoft::VisualBasic::DateInterval Interval, double Number, DateTime DateValue);" />
<MemberSignature Language="F#" Value="static member DateAdd : Microsoft.VisualBasic.DateInterval * double * DateTime -> DateTime" Usage="Microsoft.VisualBasic.DateAndTime.DateAdd (Interval, Number, DateValue)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.DateTime</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="Interval" Type="Microsoft.VisualBasic.DateInterval" />
<Parameter Name="Number" Type="System.Double" />
<Parameter Name="DateValue" Type="System.DateTime" />
</Parameters>
<Docs>
<param name="Interval">Required. A <see cref="T:Microsoft.VisualBasic.DateInterval" /> enumeration value or a string expression representing the time interval you want to add.</param>
<param name="Number">Required. Floating-point expression representing the number of intervals you want to add. It can be positive (to get date/time values in the future) or negative (to get date/time values in the past). It can contain a fractional part when <paramref name="Interval" /> specifies hours, minutes, or seconds. For other values of <paramref name="Interval" />, any fractional part of <paramref name="Number" /> is ignored.</param>
<param name="DateValue">Required. An expression representing the date and time to which the interval is to be added. <paramref name="DateValue" /> itself is not changed in the calling program.</param>
<summary>Returns a value containing a date and time value to which a specified time interval has been added.</summary>
<returns>A value containing a date and time value to which a specified time interval has been added.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You can use the `DateAdd` function to add or subtract a specified time interval from a date. For example, you can calculate a date 30 days from today or a time 45 minutes before now.
To add days to `DateValue`, you can use `DateInterval.Day`, `DateInterval.DayOfYear`, or `DateInterval.Weekday`. These are treated as equivalent because `DayOfYear` and `Weekday` are not meaningful time intervals.
The `DateAdd` function never returns an invalid date. If necessary, the day part of the resulting date is adjusted downward to the last day of the resulting month in the resulting year. The following example adds one month to January 31:
```vb
Dim NextMonth As Date = DateAdd(DateInterval.Month, 1, #1/31/1995#)
```
In this example, `DateAdd` returns `#2/28/1995#`, not `#2/31/1995#`. If `DateValue` is `#1/31/1996#`, it returns `#2/29/1996#` because 1996 is a leap year.
> [!NOTE]
> `DateAdd` uses the current calendar setting from the <xref:System.Globalization.CultureInfo.CurrentCulture%2A> property of the <xref:System.Globalization.CultureInfo> class in the <xref:System.Globalization> namespace. The default <xref:System.Globalization.CultureInfo.CurrentCulture%2A> values are determined by **Control Panel** settings.
Since every `Date` value is supported by a <xref:System.DateTime> structure, its methods give you additional options in adding time intervals. For example, you can add a fractional number of days, rounded to the nearest millisecond, to a `Date` variable as follows:
```vb
Dim NextTime As Date = Now ' Current date and time.
NextTime = NextTime.AddDays(3.4) ' Increment by 3 2/5 days.
```
The `Interval` argument can have one of the following settings.
|Enumeration value|String|Unit of time interval to add|
|-----------------------|------------|----------------------------------|
|`DateInterval.Day`|d|Day; truncated to integral value|
|`DateInterval.DayOfYear`|y|Day; truncated to integral value|
|`DateInterval.Hour`|h|Hour; rounded to nearest millisecond|
|`DateInterval.Minute`|n|Minute; rounded to nearest millisecond|
|`DateInterval.Month`|m|Month; truncated to integral value|
|`DateInterval.Quarter`|q|Quarter; truncated to integral value|
|`DateInterval.Second`|s|Second; rounded to nearest millisecond|
|`DateInterval.Weekday`|w|Day; truncated to integral value|
|`DateInterval.WeekOfYear`|ww|Week; truncated to integral value|
|`DateInterval.Year`|yyyy|Year; truncated to integral value|
## Examples
This example takes a date and, using the `DateAdd` function, displays a corresponding date a specified number of months in the future.
[!code-vb[VbVbalrFunctions#25](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrFunctions/VB/Class1.vb#25)]
]]></format>
</remarks>
<exception cref="T:System.InvalidCastException">
<paramref name="DateValue" /> is not coercible to <see langword="Date" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="Interval" /> is not valid.</exception>
<exception cref="T:System.ArgumentOutOfRangeException">Calculated date is before 00:00:00 on January 1 of the year 1, or later than 23:59:59 on December 31, 9999.</exception>
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DateDiff" />
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DatePart" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Day(System.DateTime)" />
<altmember cref="M:Microsoft.VisualBasic.Strings.Format(System.Object,System.String)" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Weekday(System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Year(System.DateTime)" />
<related type="Article" href="~/docs/visual-basic/language-reference/data-types/data-type-summary.md">Data Type Summary (Visual Basic)</related>
</Docs>
</Member>
<Member MemberName="DateAdd">
<MemberSignature Language="C#" Value="public static DateTime DateAdd (string Interval, double Number, object DateValue);" />
<MemberSignature Language="ILAsm" Value=".method public static valuetype System.DateTime DateAdd(string Interval, float64 Number, object DateValue) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.DateAdd(System.String,System.Double,System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Function DateAdd (Interval As String, Number As Double, DateValue As Object) As DateTime" />
<MemberSignature Language="C++ CLI" Value="public:
 static DateTime DateAdd(System::String ^ Interval, double Number, System::Object ^ DateValue);" />
<MemberSignature Language="F#" Value="static member DateAdd : string * double * obj -> DateTime" Usage="Microsoft.VisualBasic.DateAndTime.DateAdd (Interval, Number, DateValue)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.DateTime</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="Interval" Type="System.String" />
<Parameter Name="Number" Type="System.Double" />
<Parameter Name="DateValue" Type="System.Object" />
</Parameters>
<Docs>
<param name="Interval">Required. A <see cref="T:Microsoft.VisualBasic.DateInterval" /> enumeration value or a string expression representing the time interval you want to add.</param>
<param name="Number">Required. Floating-point expression representing the number of intervals you want to add. <paramref name="Number" /> can be positive (to get date/time values in the future) or negative (to get date/time values in the past). It can contain a fractional part when <paramref name="Interval" /> specifies hours, minutes, or seconds. For other values of <paramref name="Interval" />, any fractional part of <paramref name="Number" /> is ignored.</param>
<param name="DateValue">Required. An expression representing the date and time to which the interval is to be added. <paramref name="DateValue" /> itself is not changed in the calling program.</param>
<summary>Returns a value containing a date and time value to which a specified time interval has been added.</summary>
<returns>A value containing a date and time value to which a specified time interval has been added.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You can use the `DateAdd` function to add or subtract a specified time interval from a date. For example, you can calculate a date 30 days from today or a time 45 minutes before now.
To add days to `DateValue`, you can use `DateInterval.Day`, `DateInterval.DayOfYear`, or `DateInterval.Weekday`. These are treated as equivalent because `DayOfYear` and `Weekday` are not meaningful time intervals.
The `DateAdd` function never returns an invalid date. If necessary, the day part of the resulting date is adjusted downward to the last day of the resulting month in the resulting year. The following example adds one month to January 31:
```vb
Dim NextMonth As Date = DateAdd(DateInterval.Month, 1, #1/31/1995#)
```
In this example, `DateAdd` returns `#2/28/1995#`, not `#2/31/1995#`. If `DateValue` is `#1/31/1996#`, it returns `#2/29/1996#` because 1996 is a leap year.
> [!NOTE]
> `DateAdd` uses the current calendar setting from the <xref:System.Globalization.CultureInfo.CurrentCulture%2A> property of the <xref:System.Globalization.CultureInfo> class in the <xref:System.Globalization> namespace. The default <xref:System.Globalization.CultureInfo.CurrentCulture%2A> values are determined by **Control Panel** settings.
Since every `Date` value is supported by a <xref:System.DateTime> structure, its methods give you additional options in adding time intervals. For example, you can add a fractional number of days, rounded to the nearest millisecond, to a `Date` variable as follows:
```vb
Dim NextTime As Date = Now ' Current date and time.
NextTime = NextTime.AddDays(3.4) ' Increment by 3 2/5 days.
```
The `Interval` argument can have one of the following settings.
|Enumeration value|String|Unit of time interval to add|
|-----------------------|------------|----------------------------------|
|`DateInterval.Day`|d|Day; truncated to integral value|
|`DateInterval.DayOfYear`|y|Day; truncated to integral value|
|`DateInterval.Hour`|h|Hour; rounded to nearest millisecond|
|`DateInterval.Minute`|n|Minute; rounded to nearest millisecond|
|`DateInterval.Month`|m|Month; truncated to integral value|
|`DateInterval.Quarter`|q|Quarter; truncated to integral value|
|`DateInterval.Second`|s|Second; rounded to nearest millisecond|
|`DateInterval.Weekday`|w|Day; truncated to integral value|
|`DateInterval.WeekOfYear`|ww|Week; truncated to integral value|
|`DateInterval.Year`|yyyy|Year; truncated to integral value|
## Examples
This example takes a date and, using the `DateAdd` function, displays a corresponding date a specified number of months in the future.
[!code-vb[VbVbalrFunctions#25](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrFunctions/VB/Class1.vb#25)]
]]></format>
</remarks>
<exception cref="T:System.InvalidCastException">
<paramref name="DateValue" /> is not coercible to <see langword="Date" />.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="Interval" /> is not valid.</exception>
<exception cref="T:System.ArgumentOutOfRangeException">Calculated date is before 00:00:00 on January 1 of the year 1, or later than 23:59:59 on December 31, 9999.</exception>
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DateDiff" />
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DatePart" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Day(System.DateTime)" />
<altmember cref="M:Microsoft.VisualBasic.Strings.Format(System.Object,System.String)" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Weekday(System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Year(System.DateTime)" />
<related type="Article" href="~/docs/visual-basic/language-reference/data-types/data-type-summary.md">Data Type Summary (Visual Basic)</related>
</Docs>
</Member>
<MemberGroup MemberName="DateDiff">
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Returns a value specifying the number of time intervals between two <see langword="Date" /> values.</summary>
</Docs>
</MemberGroup>
<Member MemberName="DateDiff">
<MemberSignature Language="C#" Value="public static long DateDiff (Microsoft.VisualBasic.DateInterval Interval, DateTime Date1, DateTime Date2, Microsoft.VisualBasic.FirstDayOfWeek DayOfWeek = Microsoft.VisualBasic.FirstDayOfWeek.Sunday, Microsoft.VisualBasic.FirstWeekOfYear WeekOfYear = Microsoft.VisualBasic.FirstWeekOfYear.Jan1);" />
<MemberSignature Language="ILAsm" Value=".method public static int64 DateDiff(valuetype Microsoft.VisualBasic.DateInterval Interval, valuetype System.DateTime Date1, valuetype System.DateTime Date2, valuetype Microsoft.VisualBasic.FirstDayOfWeek DayOfWeek, valuetype Microsoft.VisualBasic.FirstWeekOfYear WeekOfYear) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval,System.DateTime,System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek,Microsoft.VisualBasic.FirstWeekOfYear)" />
<MemberSignature Language="VB.NET" Value="Public Function DateDiff (Interval As DateInterval, Date1 As DateTime, Date2 As DateTime, Optional DayOfWeek As FirstDayOfWeek = Microsoft.VisualBasic.FirstDayOfWeek.Sunday, Optional WeekOfYear As FirstWeekOfYear = Microsoft.VisualBasic.FirstWeekOfYear.Jan1) As Long" />
<MemberSignature Language="F#" Value="static member DateDiff : Microsoft.VisualBasic.DateInterval * DateTime * DateTime * Microsoft.VisualBasic.FirstDayOfWeek * Microsoft.VisualBasic.FirstWeekOfYear -> int64" Usage="Microsoft.VisualBasic.DateAndTime.DateDiff (Interval, Date1, Date2, DayOfWeek, WeekOfYear)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int64</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="Interval" Type="Microsoft.VisualBasic.DateInterval" />
<Parameter Name="Date1" Type="System.DateTime" />
<Parameter Name="Date2" Type="System.DateTime" />
<Parameter Name="DayOfWeek" Type="Microsoft.VisualBasic.FirstDayOfWeek" />
<Parameter Name="WeekOfYear" Type="Microsoft.VisualBasic.FirstWeekOfYear" />
</Parameters>
<Docs>
<param name="Interval">Required. A <see cref="T:Microsoft.VisualBasic.DateInterval" /> enumeration value or a string expression representing the time interval you want to use as the unit of difference between <paramref name="Date1" /> and <paramref name="Date2" />.</param>
<param name="Date1">Required. The first date/time value you want to use in the calculation.</param>
<param name="Date2">Required. The second date/time value you want to use in the calculation.</param>
<param name="DayOfWeek">Optional. A value chosen from the <see cref="T:Microsoft.VisualBasic.FirstDayOfWeek" /> enumeration that specifies the first day of the week. If not specified, <see cref="F:Microsoft.VisualBasic.FirstDayOfWeek.Sunday" /> is used.</param>
<param name="WeekOfYear">Optional. A value chosen from the <see cref="T:Microsoft.VisualBasic.FirstWeekOfYear" /> enumeration that specifies the first week of the year. If not specified, <see cref="F:Microsoft.VisualBasic.FirstWeekOfYear.Jan1" /> is used.</param>
<summary>Returns a long value specifying the number of time intervals between two <see langword="Date" /> values.</summary>
<returns>A long value specifying the number of time intervals between two <see langword="Date" /> values.</returns>
<remarks>
<format type="text/markdown"><]
In the preceding example, `DateDiff` returns 0 to `wD` because the difference between the two dates is less than seven days, but it returns 1 to `wY` because there is a seven-day difference between the first days of the respective calendar weeks.
- **Larger Intervals.** If `Interval` is set to `DateInterval.Year`, the return value is calculated purely from the year parts of `Date1` and `Date2`. Similarly, the return value for `DateInterval.Month` is calculated purely from the year and month parts of the arguments, and for `DateInterval.Quarter` from the quarters containing the two dates.
For example, when comparing December 31 to January 1 of the following year, `DateDiff` returns 1 for `DateInterval.Year`, `DateInterval.Quarter`, or `DateInterval.Month`, even though at most only one day has elapsed.
For cultures such as Japanese that have multiple eras, the `DateDiff` method does not return a difference in years if the difference spans two or more eras. Instead, you can calculate the difference in values returned by the <xref:System.DateTime.Year%2A> property, as shown in the following example: `date2.Year - date1.Year`.
- **Other Intervals.** Since every `Date` value is supported by a <xref:System.DateTime> structure, its methods give you additional options in finding time intervals. For example, you can use the `Subtract` method in either of its overloaded forms: <xref:System.DateTime.Subtract%2A?displayProperty=nameWithType> subtracts a <xref:System.TimeSpan> from a `Date` variable to return another `Date` value, and <xref:System.DateTime.Subtract%2A?displayProperty=nameWithType> subtracts a `Date` value to return a <xref:System.TimeSpan>. You can time a process to find out how many milliseconds it takes, as the following example shows.
[!code-vb[VbVbalrFunctions#61](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrFunctions/VB/Class1.vb#61)]
The `Interval` argument can have one of the following settings.
|Enumeration value|String value|Unit of time difference|
|-----------------------|------------------|-----------------------------|
|`DateInterval.Day`|"d"|Day|
|`DateInterval.DayOfYear`|"y"|Day|
|`DateInterval.Hour`|"h"|Hour|
|`DateInterval.Minute`|"n"|Minute|
|`DateInterval.Month`|"m"|Month|
|`DateInterval.Quarter`|"q"|Quarter|
|`DateInterval.Second`|"s"|Second|
|`DateInterval.Weekday`|"w"|Week|
|`DateInterval.WeekOfYear`|"ww"|Calendar week|
|`DateInterval.Year`|"yyyy"|Year|
The `DayOfWeek` argument can have one of the following settings.
|Enumeration value|Value|Description|
|-----------------------|-----------|-----------------|
|`FirstDayOfWeek.System`|0|First day of week specified in system settings|
|`FirstDayOfWeek.Sunday`|1|Sunday (default)|
|`FirstDayOfWeek.Monday`|2|Monday (complies with ISO standard 8601, section 3.17)|
|`FirstDayOfWeek.Tuesday`|3|Tuesday|
|`FirstDayOfWeek.Wednesday`|4|Wednesday|
|`FirstDayOfWeek.Thursday`|5|Thursday|
|`FirstDayOfWeek.Friday`|6|Friday|
|`FirstDayOfWeek.Saturday`|7|Saturday|
The `WeekOfYear` argument can have one of the following settings.
|Enumeration value|Value|Description|
|-----------------------|-----------|-----------------|
|`FirstWeekOfYear.System`|0|First week of year specified in system settings|
|`FirstWeekOfYear.Jan1`|1|Week in which January 1 occurs (default)|
|`FirstWeekOfYear.FirstFourDays`|2|Week that has at least four days in the new year (complies with ISO standard 8601, section 3.17)|
|`FirstWeekOfYear.FirstFullWeek`|3|First full week in the new year|
## Examples
This example uses the `DateDiff` function to display the number of days between a given date and today.
[!code-vb[VbVbalrFunctions#26](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrFunctions/VB/Class1.vb#26)]
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="Date1" />, <paramref name="Date2" />, or <paramref name="DayofWeek" /> is out of range.</exception>
<exception cref="T:System.InvalidCastException">
<paramref name="Date1" /> or <paramref name="Date2" /> is of an invalid type.</exception>
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DateAdd" />
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DatePart" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Day(System.DateTime)" />
<altmember cref="M:Microsoft.VisualBasic.Strings.Format(System.Object,System.String)" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Weekday(System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Year(System.DateTime)" />
<altmember cref="T:System.DateTime" />
<altmember cref="T:System.TimeSpan" />
<related type="Article" href="~/docs/visual-basic/language-reference/data-types/data-type-summary.md">Data Type Summary (Visual Basic)</related>
</Docs>
</Member>
<Member MemberName="DateDiff">
<MemberSignature Language="C#" Value="public static long DateDiff (string Interval, object Date1, object Date2, Microsoft.VisualBasic.FirstDayOfWeek DayOfWeek = Microsoft.VisualBasic.FirstDayOfWeek.Sunday, Microsoft.VisualBasic.FirstWeekOfYear WeekOfYear = Microsoft.VisualBasic.FirstWeekOfYear.Jan1);" />
<MemberSignature Language="ILAsm" Value=".method public static int64 DateDiff(string Interval, object Date1, object Date2, valuetype Microsoft.VisualBasic.FirstDayOfWeek DayOfWeek, valuetype Microsoft.VisualBasic.FirstWeekOfYear WeekOfYear) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.DateDiff(System.String,System.Object,System.Object,Microsoft.VisualBasic.FirstDayOfWeek,Microsoft.VisualBasic.FirstWeekOfYear)" />
<MemberSignature Language="VB.NET" Value="Public Function DateDiff (Interval As String, Date1 As Object, Date2 As Object, Optional DayOfWeek As FirstDayOfWeek = Microsoft.VisualBasic.FirstDayOfWeek.Sunday, Optional WeekOfYear As FirstWeekOfYear = Microsoft.VisualBasic.FirstWeekOfYear.Jan1) As Long" />
<MemberSignature Language="F#" Value="static member DateDiff : string * obj * obj * Microsoft.VisualBasic.FirstDayOfWeek * Microsoft.VisualBasic.FirstWeekOfYear -> int64" Usage="Microsoft.VisualBasic.DateAndTime.DateDiff (Interval, Date1, Date2, DayOfWeek, WeekOfYear)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int64</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="Interval" Type="System.String" />
<Parameter Name="Date1" Type="System.Object" />
<Parameter Name="Date2" Type="System.Object" />
<Parameter Name="DayOfWeek" Type="Microsoft.VisualBasic.FirstDayOfWeek" />
<Parameter Name="WeekOfYear" Type="Microsoft.VisualBasic.FirstWeekOfYear" />
</Parameters>
<Docs>
<param name="Interval">Required. A <see cref="T:Microsoft.VisualBasic.DateInterval" /> enumeration value or a string expression representing the time interval you want to use as the unit of difference between <paramref name="Date1" /> and <paramref name="Date2" />.</param>
<param name="Date1">Required. The first date/time value you want to use in the calculation.</param>
<param name="Date2">Required. The second date/time value you want to use in the calculation.</param>
<param name="DayOfWeek">Optional. A value chosen from the <see cref="T:Microsoft.VisualBasic.FirstDayOfWeek" /> enumeration that specifies the first day of the week. If not specified, <see cref="F:Microsoft.VisualBasic.FirstDayOfWeek.Sunday" /> is used.</param>
<param name="WeekOfYear">Optional. A value chosen from the <see cref="T:Microsoft.VisualBasic.FirstWeekOfYear" /> enumeration that specifies the first week of the year. If not specified, <see cref="F:Microsoft.VisualBasic.FirstWeekOfYear.Jan1" /> is used.</param>
<summary>Returns a long value specifying the number of time intervals between two <see langword="Date" /> values.</summary>
<returns>A long value specifying the number of time intervals between two <see langword="Date" /> values.</returns>
<remarks>
<format type="text/markdown"><]
In the preceding example, `DateDiff` returns 0 to `wD` because the difference between the two dates is less than seven days, but it returns 1 to `wY` because there is a seven-day difference between the first days of the respective calendar weeks.
- **Larger Intervals.** If `Interval` is set to `DateInterval.Year`, the return value is calculated purely from the year parts of `Date1` and `Date2`. Similarly, the return value for `DateInterval.Month` is calculated purely from the year and month parts of the arguments, and for `DateInterval.Quarter` from the quarters containing the two dates.
For example, when comparing December 31 to January 1 of the following year, `DateDiff` returns 1 for `DateInterval.Year`, `DateInterval.Quarter`, or `DateInterval.Month`, even though at most only one day has elapsed.
For cultures such as Japanese that have multiple eras, the `DateDiff` method does not return a difference in years if the difference spans two or more eras. Instead, you can calculate the difference in values returned by the <xref:System.DateTime.Year%2A> property, as shown in the following example: `date2.Year - date1.Year`.
- **Other Intervals.** Since every `Date` value is supported by a <xref:System.DateTime> structure, its methods give you additional options in finding time intervals. For example, you can use the `Subtract` method in either of its overloaded forms: <xref:System.DateTime.Subtract%2A?displayProperty=nameWithType> subtracts a <xref:System.TimeSpan> from a `Date` variable to return another `Date` value, and <xref:System.DateTime.Subtract%2A?displayProperty=nameWithType> subtracts a `Date` value to return a <xref:System.TimeSpan>. You can time a process to find out how many milliseconds it takes, as the following example shows.
[!code-vb[VbVbalrFunctions#61](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrFunctions/VB/Class1.vb#61)]
The `Interval` argument can have one of the following settings.
|Enumeration value|String value|Unit of time difference|
|-----------------------|------------------|-----------------------------|
|`DateInterval.Day`|"d"|Day|
|`DateInterval.DayOfYear`|"y"|Day|
|`DateInterval.Hour`|"h"|Hour|
|`DateInterval.Minute`|"n"|Minute|
|`DateInterval.Month`|"m"|Month|
|`DateInterval.Quarter`|"q"|Quarter|
|`DateInterval.Second`|"s"|Second|
|`DateInterval.Weekday`|"w"|Week|
|`DateInterval.WeekOfYear`|"ww"|Calendar week|
|`DateInterval.Year`|"yyyy"|Year|
The `DayOfWeek` argument can have one of the following settings.
|Enumeration value|Value|Description|
|-----------------------|-----------|-----------------|
|`FirstDayOfWeek.System`|0|First day of week specified in system settings|
|`FirstDayOfWeek.Sunday`|1|Sunday (default)|
|`FirstDayOfWeek.Monday`|2|Monday (complies with ISO standard 8601, section 3.17)|
|`FirstDayOfWeek.Tuesday`|3|Tuesday|
|`FirstDayOfWeek.Wednesday`|4|Wednesday|
|`FirstDayOfWeek.Thursday`|5|Thursday|
|`FirstDayOfWeek.Friday`|6|Friday|
|`FirstDayOfWeek.Saturday`|7|Saturday|
The `WeekOfYear` argument can have one of the following settings.
|Enumeration value|Value|Description|
|-----------------------|-----------|-----------------|
|`FirstWeekOfYear.System`|0|First week of year specified in system settings|
|`FirstWeekOfYear.Jan1`|1|Week in which January 1 occurs (default)|
|`FirstWeekOfYear.FirstFourDays`|2|Week that has at least four days in the new year (complies with ISO standard 8601, section 3.17)|
|`FirstWeekOfYear.FirstFullWeek`|3|First full week in the new year|
## Examples
This example uses the `DateDiff` function to display the number of days between a given date and today.
[!code-vb[VbVbalrFunctions#26](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrFunctions/VB/Class1.vb#26)]
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="Date1" />, <paramref name="Date2" />, or <paramref name="DayofWeek" /> is out of range.</exception>
<exception cref="T:System.InvalidCastException">
<paramref name="Date1" /> or <paramref name="Date2" /> is of an invalid type.</exception>
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DateAdd" />
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DatePart" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Day(System.DateTime)" />
<altmember cref="M:Microsoft.VisualBasic.Strings.Format(System.Object,System.String)" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Weekday(System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Year(System.DateTime)" />
<altmember cref="T:System.DateTime" />
<altmember cref="T:System.TimeSpan" />
<related type="Article" href="~/docs/visual-basic/language-reference/data-types/data-type-summary.md">Data Type Summary (Visual Basic)</related>
</Docs>
</Member>
<MemberGroup MemberName="DatePart">
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Returns an integer value containing the specified component of a given <see langword="Date" /> value.</summary>
</Docs>
</MemberGroup>
<Member MemberName="DatePart">
<MemberSignature Language="C#" Value="public static int DatePart (Microsoft.VisualBasic.DateInterval Interval, DateTime DateValue, Microsoft.VisualBasic.FirstDayOfWeek FirstDayOfWeekValue = Microsoft.VisualBasic.FirstDayOfWeek.Sunday, Microsoft.VisualBasic.FirstWeekOfYear FirstWeekOfYearValue = Microsoft.VisualBasic.FirstWeekOfYear.Jan1);" />
<MemberSignature Language="ILAsm" Value=".method public static int32 DatePart(valuetype Microsoft.VisualBasic.DateInterval Interval, valuetype System.DateTime DateValue, valuetype Microsoft.VisualBasic.FirstDayOfWeek FirstDayOfWeekValue, valuetype Microsoft.VisualBasic.FirstWeekOfYear FirstWeekOfYearValue) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.DatePart(Microsoft.VisualBasic.DateInterval,System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek,Microsoft.VisualBasic.FirstWeekOfYear)" />
<MemberSignature Language="VB.NET" Value="Public Function DatePart (Interval As DateInterval, DateValue As DateTime, Optional FirstDayOfWeekValue As FirstDayOfWeek = Microsoft.VisualBasic.FirstDayOfWeek.Sunday, Optional FirstWeekOfYearValue As FirstWeekOfYear = Microsoft.VisualBasic.FirstWeekOfYear.Jan1) As Integer" />
<MemberSignature Language="F#" Value="static member DatePart : Microsoft.VisualBasic.DateInterval * DateTime * Microsoft.VisualBasic.FirstDayOfWeek * Microsoft.VisualBasic.FirstWeekOfYear -> int" Usage="Microsoft.VisualBasic.DateAndTime.DatePart (Interval, DateValue, FirstDayOfWeekValue, FirstWeekOfYearValue)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="Interval" Type="Microsoft.VisualBasic.DateInterval" />
<Parameter Name="DateValue" Type="System.DateTime" />
<Parameter Name="FirstDayOfWeekValue" Type="Microsoft.VisualBasic.FirstDayOfWeek" />
<Parameter Name="FirstWeekOfYearValue" Type="Microsoft.VisualBasic.FirstWeekOfYear" />
</Parameters>
<Docs>
<param name="Interval">Required. A <see cref="T:Microsoft.VisualBasic.DateInterval" /> enumeration value or a string expression representing the part of the date/time value you want to return.</param>
<param name="DateValue">Required. The <see langword="Date" /> value that you want to evaluate.</param>
<param name="FirstDayOfWeekValue">Optional. A value chosen from the <see cref="T:Microsoft.VisualBasic.FirstDayOfWeek" /> enumeration that specifies the first day of the week. If not specified, <see cref="F:Microsoft.VisualBasic.FirstDayOfWeek.Sunday" /> is used.</param>
<param name="FirstWeekOfYearValue">Optional. A value chosen from the <see cref="T:Microsoft.VisualBasic.FirstWeekOfYear" /> enumeration that specifies the first week of the year. If not specified, <see cref="F:Microsoft.VisualBasic.FirstWeekOfYear.Jan1" /> is used.</param>
<summary>Returns an integer value containing the specified component of a given <see langword="Date" /> value.</summary>
<returns>An integer value containing the specified component of a given <see langword="Date" /> value.</returns>
<remarks>
<format type="text/markdown"><]
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="Interval" /> is not valid.</exception>
<exception cref="T:System.InvalidCastException">
<paramref name="DateValue" /> is not coercible to <see langword="Date" />.</exception>
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DateAdd" />
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DateDiff" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Day(System.DateTime)" />
<altmember cref="M:Microsoft.VisualBasic.Strings.Format(System.Object,System.String)" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Weekday(System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Year(System.DateTime)" />
<altmember cref="N:System" />
<related type="Article" href="~/docs/visual-basic/language-reference/data-types/data-type-summary.md">Data Type Summary (Visual Basic)</related>
</Docs>
</Member>
<Member MemberName="DatePart">
<MemberSignature Language="C#" Value="public static int DatePart (string Interval, object DateValue, Microsoft.VisualBasic.FirstDayOfWeek DayOfWeek = Microsoft.VisualBasic.FirstDayOfWeek.Sunday, Microsoft.VisualBasic.FirstWeekOfYear WeekOfYear = Microsoft.VisualBasic.FirstWeekOfYear.Jan1);" />
<MemberSignature Language="ILAsm" Value=".method public static int32 DatePart(string Interval, object DateValue, valuetype Microsoft.VisualBasic.FirstDayOfWeek DayOfWeek, valuetype Microsoft.VisualBasic.FirstWeekOfYear WeekOfYear) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.DatePart(System.String,System.Object,Microsoft.VisualBasic.FirstDayOfWeek,Microsoft.VisualBasic.FirstWeekOfYear)" />
<MemberSignature Language="VB.NET" Value="Public Function DatePart (Interval As String, DateValue As Object, Optional DayOfWeek As FirstDayOfWeek = Microsoft.VisualBasic.FirstDayOfWeek.Sunday, Optional WeekOfYear As FirstWeekOfYear = Microsoft.VisualBasic.FirstWeekOfYear.Jan1) As Integer" />
<MemberSignature Language="F#" Value="static member DatePart : string * obj * Microsoft.VisualBasic.FirstDayOfWeek * Microsoft.VisualBasic.FirstWeekOfYear -> int" Usage="Microsoft.VisualBasic.DateAndTime.DatePart (Interval, DateValue, DayOfWeek, WeekOfYear)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="Interval" Type="System.String" />
<Parameter Name="DateValue" Type="System.Object" />
<Parameter Name="DayOfWeek" Type="Microsoft.VisualBasic.FirstDayOfWeek" />
<Parameter Name="WeekOfYear" Type="Microsoft.VisualBasic.FirstWeekOfYear" />
</Parameters>
<Docs>
<param name="Interval">Required. A <see cref="T:Microsoft.VisualBasic.DateInterval" /> enumeration value or a string expression representing the part of the date/time value you want to return.</param>
<param name="DateValue">Required. A <see langword="Date" /> value that you want to evaluate.</param>
<param name="DayOfWeek">Optional. A value chosen from the <see cref="T:Microsoft.VisualBasic.FirstDayOfWeek" /> enumeration that specifies the first day of the week. If not specified, <see cref="F:Microsoft.VisualBasic.FirstDayOfWeek.Sunday" /> is used.</param>
<param name="WeekOfYear">Optional. A value chosen from the <see cref="T:Microsoft.VisualBasic.FirstWeekOfYear" /> enumeration that specifies the first week of the year. If not specified, <see cref="F:Microsoft.VisualBasic.FirstWeekOfYear.Jan1" /> is used.</param>
<summary>Returns an value containing the specified component of a given <see langword="Date" /> value.</summary>
<returns>An integer value containing the specified component of a given <see langword="Date" /> value.</returns>
<remarks>
<format type="text/markdown"><]
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">
<paramref name="Interval" /> is invalid.</exception>
<exception cref="T:System.InvalidCastException">
<paramref name="DateValue" /> is not coercible to <see langword="Date" />.</exception>
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DateAdd" />
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DateDiff" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Day(System.DateTime)" />
<altmember cref="M:Microsoft.VisualBasic.Strings.Format(System.Object,System.String)" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Weekday(System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Year(System.DateTime)" />
<altmember cref="N:System" />
<related type="Article" href="~/docs/visual-basic/language-reference/data-types/data-type-summary.md">Data Type Summary (Visual Basic)</related>
</Docs>
</Member>
<Member MemberName="DateSerial">
<MemberSignature Language="C#" Value="public static DateTime DateSerial (int Year, int Month, int Day);" />
<MemberSignature Language="ILAsm" Value=".method public static valuetype System.DateTime DateSerial(int32 Year, int32 Month, int32 Day) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.DateSerial(System.Int32,System.Int32,System.Int32)" />
<MemberSignature Language="VB.NET" Value="Public Function DateSerial (Year As Integer, Month As Integer, Day As Integer) As DateTime" />
<MemberSignature Language="C++ CLI" Value="public:
 static DateTime DateSerial(int Year, int Month, int Day);" />
<MemberSignature Language="F#" Value="static member DateSerial : int * int * int -> DateTime" Usage="Microsoft.VisualBasic.DateAndTime.DateSerial (Year, Month, Day)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.DateTime</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="Year" Type="System.Int32" />
<Parameter Name="Month" Type="System.Int32" />
<Parameter Name="Day" Type="System.Int32" />
</Parameters>
<Docs>
<param name="Year">Required. Integer expression from 1 through 9999. However, values below this range are also accepted. If <paramref name="Year" /> is 0 through 99, it is interpreted as being between 1930 and 2029, as explained in the "Remarks" section below. If <paramref name="Year" /> is less than 1, it is subtracted from the current year.</param>
<param name="Month">Required. Integer expression from 1 through 12. However, values outside this range are also accepted. The value of <paramref name="Month" /> is offset by 1 and applied to January of the calculated year. In other words, (<paramref name="Month" /> - 1) is added to January. The year is recalculated if necessary. The following results illustrate this effect:
If <paramref name="Month" /> is 1, the result is January of the calculated year.
If <paramref name="Month" /> is 0, the result is December of the previous year.
If <paramref name="Month" /> is -1, the result is November of the previous year.
If <paramref name="Month" /> is 13, the result is January of the following year.</param>
<param name="Day">Required. Integer expression from 1 through 31. However, values outside this range are also accepted. The value of <paramref name="Day" /> is offset by 1 and applied to the first day of the calculated month. In other words, (<paramref name="Day" /> - 1) is added to the first of the month. The month and year are recalculated if necessary. The following results illustrate this effect:
If <paramref name="Day" /> is 1, the result is the first day of the calculated month.
If <paramref name="Day" /> is 0, the result is the last day of the previous month.
If <paramref name="Day" /> is -1, the result is the penultimate day of the previous month.
If <paramref name="Day" /> is past the end of the current month, the result is the appropriate day of the following month. For example, if <paramref name="Month" /> is 4 and <paramref name="Day" /> is 31, the result is May 1.</param>
<summary>Returns a <see langword="Date" /> value representing a specified year, month, and day, with the time information set to midnight (00:00:00).</summary>
<returns>A <see langword="Date" /> value representing a specified year, month, and day, with the time information set to midnight (00:00:00).</returns>
<remarks>
<format type="text/markdown"><]
]]></format>
</remarks>
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.DateValue(System.String)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Day(System.DateTime)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Month(System.DateTime)" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.TimeSerial(System.Int32,System.Int32,System.Int32)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.TimeValue(System.String)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Weekday(System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Year(System.DateTime)" />
<altmember cref="N:System" />
<related type="Article" href="~/docs/visual-basic/language-reference/data-types/data-type-summary.md">Data Type Summary (Visual Basic)</related>
</Docs>
</Member>
<Member MemberName="DateString">
<MemberSignature Language="C#" Value="public static string DateString { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property string DateString" />
<MemberSignature Language="DocId" Value="P:Microsoft.VisualBasic.DateAndTime.DateString" />
<MemberSignature Language="VB.NET" Value="Public Property DateString As String" />
<MemberSignature Language="C++ CLI" Value="public:
 static property System::String ^ DateString { System::String ^ get(); void set(System::String ^ value); };" />
<MemberSignature Language="F#" Value="member this.DateString : string with get, set" Usage="Microsoft.VisualBasic.DateAndTime.DateString" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Returns or sets a string value representing the current date according to your system.</summary>
<value>Returns or sets a string value representing the current date according to your system.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
`DateString` returns the system date in the MM-dd-yyyy format, which uses the abbreviated month name. The accepted formats for the date are M-d-yyyy, M-d-y, M/d/yyyy, and M/d/y. This is true for all system locales except those that use a double-byte character set (DBCS). If the system locale uses a double-byte character set, `DateString` returns the system date in the yyyy-MM-dd format. The system locale is set by using the **Clock, Language, and Region** item in **Control Panel**.
**Note** The `DateString` property returns the system date only in the yyyy-MM-dd format for the `zh` (Chinese simplified), `ko` (Korean), and `ja` (Japanese) system locales if you are running Visual Basic within Silverlight.
To get or set the current system time as a `String`, use the <xref:Microsoft.VisualBasic.DateAndTime.TimeString%2A> property.
To get the current system date or time in the format of your locale, or in a custom format, supply the <xref:Microsoft.VisualBasic.DateAndTime.Now%2A> property to the <xref:Microsoft.VisualBasic.Strings.Format%2A> function, specifying either a predefined or user-defined date/time format. The following example demonstrates this.
```vb
MsgBox("The formatted date is " & Format(Now, "dddd, d MMM yyyy"))
```
To access the current system date as a `Date`, use the <xref:Microsoft.VisualBasic.DateAndTime.Today%2A> property.
> [!IMPORTANT]
> Setting the system date or time requires unmanaged code permission, which might affect its execution in partial-trust situations. For more information, see <xref:System.Security.Permissions.SecurityPermission> and [Code Access Permissions](https://msdn.microsoft.com/library/e5ae402f-6dda-4732-bbe8-77296630f675).
## Examples
The following example uses the `DateString` property to display the current system date.
[!code-vb[VbVbalrDateProperties#1](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrDateProperties/VB/Module1.vb#1)]
]]></format>
</remarks>
<exception cref="T:System.InvalidCastException">Invalid format used to set the value of <see cref="T:Microsoft.VisualBasic.DateAndTime.DateString" />.</exception>
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.TimeString" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Today" />
<altmember cref="T:System.DateTime" />
</Docs>
</Member>
<Member MemberName="DateValue">
<MemberSignature Language="C#" Value="public static DateTime DateValue (string StringDate);" />
<MemberSignature Language="ILAsm" Value=".method public static valuetype System.DateTime DateValue(string StringDate) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.DateValue(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Function DateValue (StringDate As String) As DateTime" />
<MemberSignature Language="C++ CLI" Value="public:
 static DateTime DateValue(System::String ^ StringDate);" />
<MemberSignature Language="F#" Value="static member DateValue : string -> DateTime" Usage="Microsoft.VisualBasic.DateAndTime.DateValue StringDate" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.DateTime</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="StringDate" Type="System.String" />
</Parameters>
<Docs>
<param name="StringDate">Required. string expression representing a date/time value from 00:00:00 on January 1 of the year 1 through 23:59:59 on December 31, 9999.</param>
<summary>Returns a <see langword="Date" /> value containing the date information represented by a string, with the time information set to midnight (00:00:00).</summary>
<returns>A <see langword="Date" /> value containing the date information represented by a string, with the time information set to midnight (00:00:00).</returns>
<remarks>
<format type="text/markdown"><]
]]></format>
</remarks>
<exception cref="T:System.InvalidCastException">
<paramref name="StringDate" /> includes invalid time information.</exception>
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.DateSerial(System.Int32,System.Int32,System.Int32)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Day(System.DateTime)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Month(System.DateTime)" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.TimeSerial(System.Int32,System.Int32,System.Int32)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.TimeValue(System.String)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Weekday(System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Year(System.DateTime)" />
<altmember cref="T:System.DateTime" />
<related type="Article" href="~/docs/visual-basic/language-reference/data-types/data-type-summary.md">Data Type Summary (Visual Basic)</related>
</Docs>
</Member>
<Member MemberName="Day">
<MemberSignature Language="C#" Value="public static int Day (DateTime DateValue);" />
<MemberSignature Language="ILAsm" Value=".method public static int32 Day(valuetype System.DateTime DateValue) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.Day(System.DateTime)" />
<MemberSignature Language="VB.NET" Value="Public Function Day (DateValue As DateTime) As Integer" />
<MemberSignature Language="C++ CLI" Value="public:
 static int Day(DateTime DateValue);" />
<MemberSignature Language="F#" Value="static member Day : DateTime -> int" Usage="Microsoft.VisualBasic.DateAndTime.Day DateValue" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="DateValue" Type="System.DateTime" />
</Parameters>
<Docs>
<param name="DateValue">Required. A <see langword="Date" /> value from which you want to extract the day.</param>
<summary>Returns an integer value from 1 through 31 representing the day of the month.</summary>
<returns>An integer value from 1 through 31 representing the day of the month.</returns>
<remarks>
<format type="text/markdown"><]
`Day` is qualified to distinguish it from the <xref:System.Windows.Forms.Day?displayProperty=nameWithType> enumeration.
]]></format>
</remarks>
<altmember cref="Overload:Microsoft.VisualBasic.DateAndTime.DatePart" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Month(System.DateTime)" />
<altmember cref="P:Microsoft.VisualBasic.DateAndTime.Now" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Weekday(System.DateTime,Microsoft.VisualBasic.FirstDayOfWeek)" />
<altmember cref="M:Microsoft.VisualBasic.DateAndTime.Year(System.DateTime)" />
<altmember cref="T:System.DateTime" />
<altmember cref="T:System.ArgumentException" />
<altmember cref="T:System.ArgumentOutOfRangeException" />
</Docs>
</Member>
<Member MemberName="Hour">
<MemberSignature Language="C#" Value="public static int Hour (DateTime TimeValue);" />
<MemberSignature Language="ILAsm" Value=".method public static int32 Hour(valuetype System.DateTime TimeValue) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.DateAndTime.Hour(System.DateTime)" />
<MemberSignature Language="VB.NET" Value="Public Function Hour (TimeValue As DateTime) As Integer" />
<MemberSignature Language="C++ CLI" Value="public:
 static int Hour(DateTime TimeValue);" />
<MemberSignature Language="F#" Value="static member Hour : DateTime -> int" Usage="Microsoft.VisualBasic.DateAndTime.Hour TimeValue" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>7.0.5000.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>