Skip to main content
Question

Is it possible to get the last day of the last month as a date?

  • November 11, 2022
  • 7 replies
  • 754 views

Forum|alt.badge.img+12

for example, if today's month: 11.month-november, it should give me 31.10.2022

if its 10.month-october, it should give me 30.09.2022

7 replies

Forum|alt.badge.img+12
  • Author
  • Mission Commander | Tier 5
  • 520 replies
  • November 11, 2022

I found out the solution.

I will just get the firstday of the month, it will give me 01.11.2022

and i will substract 1 day from that value, so it will give me the last of the last month.


  • Navigator | Tier 3
  • 22 replies
  • November 14, 2022

Pls post code screenshot of solution.


Raul Jaimes
Forum|alt.badge.img+9
  • Navigator | Tier 3
  • 494 replies
  • November 15, 2022

i have created a csv file with all the last day of month. The bot read the content by month and year and get the last day. inputs are year and month.

 

year,month,end_of_month

2022, 01, 31.01.2022

2022, 02, 28.02.2022

..

2024, 01, 31.01.2024

2024, 02, 29, 29.01.2024

..

 

Consider the leap-year.

 

Regards

 


kisho
Navigator | Tier 3
Forum|alt.badge.img+5
  • Navigator | Tier 3
  • 12 replies
  • March 25, 2025

I hope the screenshot will assist you in determining the exact answer to the question above. 

 

 

 


Forum|alt.badge.img+4

Hi 

Semih 3318 wrote:

for example, if today's month: 11.month-november, it should give me 31.10.2022

if its 10.month-october, it should give me 30.09.2022

Hi ​@Semih 3318
@kisho already provided the best approach for your query. But if you’re looking to stretch and try another package use date-time utilities.

Please download this package first.

https://botstore.automationanywhere.com/bot/a2019-datetime-utilities

Datetime Utilities helps me a lot in most of my projects that require date manipulation and date processing.

Once you have downloaded and imported the package to your control room, check the overall solution below.

Overall Solution:
 

 


Forum|alt.badge.img+12
  • Author
  • Mission Commander | Tier 5
  • 520 replies
  • March 31, 2025

Hi ​@jeven.delacruz  thank you for your reply.

For this, datetime package in AA as my reply in my question is enough actually, no need to download a bot from botstore. 


Dineshkumar Muthu
Navigator | Tier 3
Forum|alt.badge.img+9

Hi ​@Semih 3318 

You can calculate the last day of the previous month using both SQL and an Excel database query:

SQL Query

sql

SELECT 
    DATEADD(DAY, -1, CAST(FORMAT(GETDATE(), 'yyyy-MM-01') AS DATE)) AS LastDayPrevMonth;
  • Retrieves the last day of the previous month by going to the first day of the current month and subtracting one day.

Excel Database Query

If you're using Excel as a database and querying through MS Access or Excel SQL engine, you can use the following query:

sql

SELECT 
    DateSerial(Year(Date()), Month(Date()), 0) AS LastDayPrevMonth
FROM 
    [Sheet1$];
  • Explanation:

    • DateSerial(Year(Date()), Month(Date()), 0): Computes the last day of the previous month by setting the day to 0 of the current month.

In both cases:

  • The SQL Query is perfect for typical SQL databases like SQL Server, MySQL, or others.

  • The Excel Query can be used for queries in tools like MS Access or directly manipulating Excel sheets using ODBC connections.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings