How to get the date from a specific day till today?

I want to get the date from a specific day, like i have checked the date from database that the last run date was 12-Jul-23 and i have to get the dates from 12-Jul-23 till today 26-Jul-23 for 14 days, these dates might be change for 2 days, 3 days, 15 days, 2 months etc.

Hi @connect360

Try this:

  1. Get last run date from database and store it in lastRunDate datetime variable.
  2. Get current date by using datetime.now.date and store it in currentDate datetime variable
dateList = (From i In Enumerable.Range(0, CInt((currentDate - lastRunDate).TotalDays) + 1)
Select lastRunDate.AddDays(i)).ToList()

Note: dateList is a List<DateTime> variable

1 Like

Hi @connect360

Check out the below xaml file.

Sequence20.xaml (9.8 KB)

Hope it works!!

The last run date is in data table and current date is in string how to convert/handle them??
last_run (datetime) = lastrun_db_date(datatable) canot convert datatable into date.

and i need the date in below format
2-Jul-23
3-Jul-23

@connect360

Try this:

'Converting string to datetime
lastRunDate = DateTime.Parse(lastRunDateString)
currentDate = DateTime.Parse(currentDateString)

dateList = (From i In Enumerable.Range(0, CInt((currentDate - lastRunDate).TotalDays) + 1)
            Select lastRunDate.AddDays(i).ToString("d-MMM-yy")).ToList()

1 Like

The data table returns the value with headers. How to remove headers?? and save the date as string?

File_Date
2-Jun-23

@connect360

From where are you getting the date?
Excel or Database?

1 Like

I am getting from database.

The dateList variable returns nothing just (System.Collections.Generic.List`1[System.DateTime])

dateList = (From i In Enumerable.Range(0, CInt((currentDate - lastRunDate).TotalDays) + 1)
Select lastRunDate.AddDays(i).ToString(β€œd-MMM-yy”)).ToList()

@connect360

If you are getting from database then it will give the value only right, why are you getting the headers?
And the date you are getting is date variable or string variable?

Use for each loop to print the values or debug the code and check local panel for output.

I am getting the output for 10 days in my case:
{ β€œ16-Jul-23”, β€œ17-Jul-23”, β€œ18-Jul-23”, β€œ19-Jul-23”, β€œ20-Jul-23”, β€œ21-Jul-23”, β€œ22-Jul-23”, β€œ23-Jul-23”, β€œ24-Jul-23”, β€œ25-Jul-23”, β€œ26-Jul-23”

Can you please share the syntax pattern or screen shots how to use and how it works?

@connect360


(From i In Enumerable.Range(0, CInt((currentDate - lastRunDate).TotalDays) + 1) Select lastRunDate.AddDays(i).ToString("d-MMM-yy")).ToList()

In lastRunDate variable, I just add 10 days to current date to get the 10 days range.

1 Like

It returns me in below format not as required??

07/04/2023 00:00:00
07/06/2023 00:00:00

@connect360

(From i In Enumerable.Range(0, CInt((currentDate - lastRunDate).TotalDays) + 1) Select lastRunDate.AddDays(i).ToString(β€œd-MMM-yy”)).ToList()

Check once I added .ToString(β€œd-MMM-yy”) to first code, please check and get back to me. This will give only dates with d-MMM-yy format only.

error : List(ofstring) cannot be converted to List(ofdate)

@connect360

the output list type is list

that is list of datetime

image

Change it to list<String>

Error
Assign: Expression Activity type β€˜VisualBasicValue`1’ requires compilation in order to run. Please ensure that the workflow has been compiled.

image

System.NotSupportedException: Expression Activity type 'VisualBasicValue1' requires compilation in order to run. Please ensure that the workflow has been compiled. at System.Activities.Expressions.CompiledExpressionInvoker.InvokeExpression(ActivityContext activityContext) at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context)
at System.Activities.CodeActivity`1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResol