DATE Function: Print the Last Date of a Month

Syntax:
=DATE (year, month, day)

This function is used to create a valid date from year, month, and day. This will display a serial number that represents a particular date in Excel.

Arguments:
year - The year to use when creating the date.
month - The month to use when creating the date.
day - The day to use when creating the date.

Usage notes:
DATE returns a date serial number. Format the result as a date to display as a date.

If year is between zero and 1900, Excel will add 1900 to the year.

Month can be greater than 12 and less than zero. If month is greater than 12, Excel will add month to the first month in the specified year. If month is less than or equal to zero, Excel will subtract the absolute value of month plus 1 (i.e. ABS(month) + 1) from the first month of the specified year.

Day can be positive or negative. If day is greater than the days in the specified month, Excel will add day to the first day of the specified month. If day is less than or equal to zero, Excel will subtract the absolute value of day plus 1 (i.e. ABS(day) + 1) from the first day of the specified month.

=DATE(year,1,daynum)
Related formulas
Convert date to Julian format
To get a real date from day number, or "nth day of year" you can use the DATE function.

In the example shown, the formula in C5 is:

=DATE(2015,1,B5)
How this formula works

The DATE function build dates from separate year, month, and day values. One of it's tricks is the ability to roll forward to correct dates when given days and months that are "out of range".

For example, DATE returns April 9, 2016 with the following arguments:

=DATE(2016,1,100)
There is no 100th day in January, so DATE simple moves forward 100 days from January 1 and figures returns the correct date.

The formula on this page takes advantage of this behavior. The year assumed to be 2015 in this case, so 2015 is hard-coded for year, and 1 is used for month. The day value comes from column B, and the DATE function calculates the date as explained above.

Extracting a year value from a Julian date

If you have a date in a Julian format, for example, 10015, where the format is "dddyy", you can adapt the formula as follows:

=DATE(RIGHT(A1,2),1,LEFT(A1,3))

Here, we use RIGHT to extract the 2 characters from the right for year, and LEFT to extract 3 characters from the left for day. Month is supplied as 1, like the first example.

For example: 

Find the last date of a month:

=DATE(YEAR(date),MONTH(date)+1,0)

=DATE($E$1,MONTH(DATEVALUE($D$1&" 1"))+1,0)
$E$1  has the Year value.
$D$1 has the Month Name.

For more info regarding YEAR and DATEVALUE functions please check YEAR and DATEVALUE

No comments:

Post a Comment

Thank You.

https://linwintech.blogspot.com/