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" = 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 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(2021, 8, 1) '= 01/08/2021
Debug.Print DateSerial(2021 - 8, 12 - 2, 5) '= 05/10/2013
Debug.Print DateSerial(2021, 12, 2) '= 02/12/2021
Debug.Print DateSerial(2021, 12 + 2, 2 + 30) '= 04/03/2022
Debug.Print DateSerial(1900, 2, 29) = 1 / 3 / 1900 '= 29 days added
Dim lserial As Long
lserial = DateSerial(2021, 7, 2)
Debug.Print lserial '= 44379
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited Top