Hello @NISHITHA , You can do this in 3 ways using UiPath.
- UiPath Studio
- Custom Activity or C# or Vb Code
- Push Data in data base via UiPath using SQL Query you can achieve this task. [My Recommendation but you try first two]
This workflow utilizes built-in UiPath activities for a visually clear and intuitive solution:
Professional Solutions for Extracting Last Week’s Dates (Monday & Sunday) from Last Year
This document presents three professional approaches to extract the previous week’s Monday and Sunday dates from last year, considering the current date:
1. UiPath Workflow:
Prerequisites:
- UiPath Studio (licensed version recommended)
- Familiarity with UiPath activities
Solution:
This workflow utilizes built-in UiPath activities for a visually clear and intuitive solution:
-
Get Today’s Date:
- Employ the
Get System Date
activity to retrieve the current system date and store it in a variable named currentDate
.
-
Calculate Last Year’s Date:
- Utilize the
Add Years
activity to subtract one year from currentDate
. Assign the result to a variable named lastYearDate
.
-
Get Week Start and End Dates:
- Apply the
Get Week Start and End Dates
activity:
- Input
lastYearDate
as the base date.
- Set
OutputFormat
to yyyy-MM-dd
(or a preferred format) for consistent date representation.
- Store the output in variables:
lastWeekStartDate
for Monday and lastWeekEndDate
for Sunday.
Explanation:
- The
Get System Date
activity ensures the workflow reflects the current date.
- The
Add Years
activity accurately calculates the corresponding date from last year.
- The
Get Week Start and End Dates
activity efficiently extracts the previous week’s start (Monday) and end (Sunday) dates with user-defined formatting.
Output:
The workflow outputs the lastWeekStartDate
and lastWeekEndDate
, representing the previous Monday and Sunday of last year.
Benefits:
- Visually clear and easy to maintain in UiPath Studio.
- User-friendly date format customization.
- Built-in activities for robust date manipulation.
2. Custom Activity Code(C# or VB):
Prerequisites:
- A C# development environment (e.g., Visual Studio)
- Solid understanding of C# data/time functionalities
- know about convert DLL to UiPath Packages
Solution:
This code snippet provides a well-structured approach:
using System;
public class LastWeekDates
{
public static void Main(string[] args)
{
DateTime currentDate = DateTime.Today;
DateTime lastYearDate = currentDate.AddYears(-1);
DateTime lastWeekStartDate = lastYearDate.AddDays(-(int)currentDate.DayOfWeek);
DateTime lastWeekEndDate = lastWeekStartDate.AddDays(6);
Console.WriteLine("Last Week Start Date (Monday): {0:yyyy-MM-dd}", lastWeekStartDate);
Console.WriteLine("Last Week End Date (Sunday): {0:yyyy-MM-dd}", lastWeekEndDate);
}
}
Explanation:
- The code leverages
DateTime.Today
to retrieve the current date.
AddYears(-1)
calculates the last year’s date accurately.
AddDays(-(int)currentDate.DayOfWeek)
adjusts lastYearDate
to the previous Monday.
AddDays(6)
adds six days to get the previous Sunday.
- Formatted dates are displayed using
Console.WriteLine
with clear labels.
Benefits:
- Well-structured and readable code.
- Efficient date manipulation using C# functionalities.
- Flexibility for further processing or integration.
3. Database (SQL Server Example):
Prerequisites:
- A SQL Server database management system
- Proficiency in writing SQL queries
Solution:
This SQL query implements efficient date calculations:
DECLARE @currentDate DATE = GETDATE();
DECLARE @lastYearDate DATE = DATEADD(YEAR, -1, @currentDate);
SELECT
DATEADD(DAY, -DATEPART(dw, @lastYearDate), @lastYearDate) AS LastWeekStartDate,
DATEADD(DAY, 6 - DATEPART(dw, @lastYearDate), @lastYearDate) AS LastWeekEndDate
Explanation:
- The query declares variables for the current and last year’s dates.
DATEADD(YEAR, -1, @currentDate)
calculates the date from last year.
DATEPART(dw, @lastYearDate)
extracts the day of the week from lastYearDate
.
DATEADD(DAY, -DATEPART(dw, @lastYearDate), @lastYearDate)
adjusts lastYearDate
to the previous Monday.
DATEADD(DAY, 6 - DATEPART(dw, @lastYearDate), @lastYearDate)
adds six days to get the previous Sunday.
- The query
@NISHITHA I was just given a example of test cases but you can try this your own and know you should got the idea how to solve this.