Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Is there a way to find last date of month using any function? Like 03/15/2017 should return 03/31/2017? (SAP)
You can use the DateSerial() function in SAP to find the last date of any month. This function returns a Date value for the specified year, month and day and also handles relative Date expressions.
Arguments
- year ? A whole number or numeric expression representing a year, example: 1996.
- month ? A whole number or numeric expression representing a month, example: 12 for December.
- day ? A whole number or numeric expression representing a day of the month, example: 5.
Returns
A Date value.
Basic DateSerial Examples
The DateSerial() function can handle various date expressions ?
DateSerial(2000, 6, 15) DateSerial(2004, 1 - 7, 15) DateSerial(2008, 1, 166)
Finding Last Date of Month
To find the last date of a month, the technique is to find the first day of the next month and then subtract one day. Here's the formula ?
DateSerial(
year({table.date}),
month({table.date}) + 1,
1
) - 1
How It Works
For the input date 03/15/2017 ?
-
year({table.date})extracts 2017 -
month({table.date}) + 1gives 4 (April) -
DateSerial(2017, 4, 1)returns April 1, 2017 - Subtracting 1 day gives March 31, 2017
You can refer to the DateSerial documentation for more details about this function.
Conclusion
The DateSerial() function provides an effective way to find the last date of any month by calculating the first day of the next month and subtracting one day, making it useful for date range calculations in SAP applications.
