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:
- Get last run date from database and store it in
lastRunDate
datetime variable. - Get current date by using
datetime.now.date
and store it incurrentDate
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
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
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()
The data table returns the value with headers. How to remove headers?? and save the date as string?
File_Date
2-Jun-23
From where are you getting the date?
Excel or Database?
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()
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?
(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.
It returns me in below format not as required??
07/04/2023 00:00:00
07/06/2023 00:00:00
(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)
the output list type is list
that is list of datetime
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.
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.VisualBasicValue
1.Execute(CodeActivityContext context)
at System.Activities.CodeActivity`1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResol