DATESERIAL |
DATESERIAL(year, month, day) |
Returns the date given a year, month and day (Date). |
year | The year between 1 and 9999, inclusively (Integer). |
month | The month between 1 and 12 (Integer). |
day | The day between 1 and 31 (Integer). |
REMARKS |
* This function can accept values outside the normal range. * 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, are interpreted as the years 2000-2029. * If "year" is between 30 and 99 are interpreted as the years 1930-1999. * If "year" is between 0 and 99, inclusive, are interpreted as the years 1400-1499. * If "year" < 1, then this number is subtracted from the current year. * If "month" = 0, then it represents December of the previous year. * If "month" = 13, then it represents January of the next year. * 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 day depending on the actual date. * If "day" = -1, then it represents November of the previous year. * A practical use of this function is to identify leap years << User Defined Function >>. * 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(2024, 8, 1) '= 01/08/2024
Debug.Print DateSerial(2024 - 8, 12 - 2, 5) '= 05/10/2016
Debug.Print DateSerial(2024, 12, 2) '= 02/12/2024
Debug.Print DateSerial(2024, 12 + 2, 2 + 30) '= 04/03/2025
Debug.Print DateSerial(1900, 2, 29) '= 01/03/1900
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