DATESERIAL

DATESERIAL(year, month, day)

Returns the date given a year, month and day (Date).


yearThe year between 1 and 9999, inclusively (Integer).
monthThe month between 1 and 12 (Integer).
dayThe day between 1 and 31 (Integer).

REMARKS
* This function can accept values outside the normal range.
* This function uses your Local Settings for the format of the returned value.
* For example if you pass in the year 2020 and the month 14, it will return a date in the second month of 2021 (ie it will add 14 months).
* You can specify relative dates for each argument using any numeric expression that represents some number of days, months, or years before or after a certain date.
* When an argument exceeds the accepted range, it increments to the next larger unit as appropriate.
* If any argument is outside -32,768 to 32,767, then an error occurs.
* The "year" should be entered as a four-digit year.
* If "year" is between 0 and 29, inclusive, these are interpreted as the years 2000-2029.
* If "year" is between 30 and 99, inclusive, these are interpreted as the years 1930-1999.
* If "year" < 1, then this number is subtracted from the current year.
* If "month" = 12, then it represents December of the current year.
* If "month" = 13, then it represents January of the next year.
* If "month" < 1, then this number is subtracted from the current year.
* If "month" = 0, then it represents December of the previous year.
* If "month" = -1, then it represents November of the previous year.
* If "day" = 1, then it represents the first day of the month
* If "day" = 29 and the month is February and its not a leap year, then this represents 1 March.
* If "day" = 35, then it represents one month plus a certain number of days (6,7 or 8) depending on the year.
* If "day" = 0, then it represents the last day of the previous month.
* A practical use of this function is to identify leap years << User Defined Function >>.
* You can use the CDATE function to return an expression converted to a Date data type.
* You can use the DATE function to return the current system date.
* You can use the DATEADD function to return the date with a specified time interval added.
* You can use the DATEDIFF function to return the number of a given time interval between two specified dates.
* You can use the DATEPART function to return the specified part of a given date.
* You can use the DATEVALUE function to return the date given a string representation of a date.
* You can use the FORMAT function to return a text string of a number or date in a particular format.
* The equivalent .NET function is [[Microsoft.VisualBasic.DateAndTime.DateSerial]]
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print DateSerial(1, 1, 1)                    '= 01/01/2001  
Debug.Print DateSerial(1900, 2, 29) '= 01/03/1900
Debug.Print DateSerial(2024, 8, 1) '= 01/08/2024
Debug.Print DateSerial(2024, 12, 2) '= 02/12/2024

Debug.Print DateSerial(2024 - 8, 12 - 2, 5) '= 05/10/2016
Debug.Print DateSerial(2024, 12 + 2, 2 + 30) '= 04/03/2025

Debug.Print DateSerial(2025, 1, 1) '= 01/01/2025
Debug.Print DateSerial(2025, 12, 1) '= 01/12/2025

Debug.Print DateSerial(2025, 0, 1) '= 01/12/2024
Debug.Print DateSerial(2025, -1, 1) '= 01/11/2024

Debug.Print DateSerial(2025, 1, 28) '= 28/01/2025
Debug.Print DateSerial(2025, 1, 0) '= 31/12/2024
Debug.Print DateSerial(2025, 1, -1) '= 30/12/2024

Dim lserial As Long
lserial = DateSerial(2024, 7, 2)
Debug.Print lserial '= 45475

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top