Hello Team,
Kindly help me with an solution regarding how to get 1st date and last date of every month in an order for previous year 2023 ?
Thank you,
Hello Team,
Kindly help me with an solution regarding how to get 1st date and last date of every month in an order for previous year 2023 ?
Thank you,
Read Excel File containing dates for 2023
Create a DataTable to store first and last dates
For each month (1 to 12)
Get the number of days in the month using DateTime.DaysInMonth(2023, current_month)
Create a DateTime object for the first date of the month: new DateTime(2023, current_month, 1)
Create a DateTime object for the last date of the month: new DateTime(2023, current_month, days_in_month)
Add the first and last dates to the DataTable
Output the DataTable or Save it to an Excel file
Hi @Samje
Output:
Since Data is huge, I wrote it into Notepad file.
Sequence11.xaml (10.2 KB)
Hope this meets your requirement
Regards
Hey @Samje , You can try using the following LINQ:
(From item in Enumerable.Range(1,12)
Let startDate=cdate(item.ToString+"/1/"+now.AddYears(-1).Year.ToString)
Let endDate=Cdate(item.ToString+"/"+DateTime.DaysInMonth(Now.AddYears(-1).year,item).ToString+"/"+now.AddYears(-1).Year.ToString)
Select {startDate,endDate}.ToList).ToList
The expected output is as below:
The output will be a list of (DateTime,DateTime), as in each item in the list will contain the start and end dates.
Regards
Hi varun,
Thank you for the solution.
Regards,
Sam
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.