Rhys18
(Rizky Albert Hartono)
June 30, 2022, 9:09am
1
Hi,
I have a task to pass this code inside excel with a dictionary :
New datetime(now.Date.Year, now.Date.Month,1).AddMonths(0).AddDays(-1).ToString(“yyyy-MM-dd”)
and I am using assign activity with a variable strMonth (var type is string).
When I writeline,
I got this :
strMonth : New datetime(now.Date.Year, now.Date.Month,1).AddMonths(0).AddDays(-1).ToString(“yyyy-MM-dd”)
My expected output :
strMonth : 2022-05-31
How to make the config value Not as string? Any solution? Thanks
Hi!
Convert that string to Date time and pass that value:
Try this:
Datetime.ParseExact(Strinput.ToString, “MM-dd-yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd”)
Then user your expression here:
Regards,
NaNi
Rhys18
(Rizky Albert Hartono)
June 30, 2022, 9:20am
3
Hi, I tried to combine with the solution you give and I got this error instead :
This is my code :
strMonth = Datetime.ParseExact(config_excel("prev_month").ToString, “MM-dd-yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd”)
Hey!
Can you show me the input date ?
Regards,
NaNi
Rhys18
(Rizky Albert Hartono)
June 30, 2022, 9:24am
5
Hi,
so this is my original code :
then there’s a change on the New.Datetime declare need to be stored in dictionary. When I use dictionary I receive this output :
It got converted t o string. How to make it not as a string value?
Expected output should be : 2022-05-31
Hi!
When your creating the Table with Column with Data Type. You mentioned Varchar so this will takes the input as String or integer values not Date and time values…
So Don’t Convert the String to Date Time. This will give you the same error…
Either you have to change the Data Type of that column or don’t convert this to DateTime variable
Regards,
NaNi
Hello @Rhys18
Please check the below post. It can give you an overview of the steps required.
Rhys18
(Rizky Albert Hartono)
June 30, 2022, 9:33am
8
Hi, @THIRU_NANI @Rahul_Unnikrishnan
Actually there is no data table… It’s just a passing to dictionary, but when the dictionary value got called using a variable, the variable read the dictionary value as String.
Can we not read the value as string?
Instead of the output is
“New DateTime.Now.ToString”
to
New DateTime.Now.ToString
Is it possible?
From the dictionary you are getting the value as string but inorder to do the calculation you can convert that string to Datetime variable.
Your variable : it is the value which you are getting from dictionary
required format: format you can set as per the format of the string you are getting “dd/MMM/yyyy”…like this
Datetime.parseexact(Your variable,required format,system.globalization.cultureinfo.invariantculture)
Hey!
Show us the input date format which is there in Dictionary!
Not expected output
Regards,
NaNi
Rhys18
(Rizky Albert Hartono)
June 30, 2022, 9:42am
11
This is the dictionary
I want it to be like this :
strMonth = New datetime(now.Date.Year, now.Date.Month,1).AddMonths(0).AddDays(-1).ToString(“yyyy-MM-dd”)
Instead, I got this :
strMonth = “New datetime(now.Date.Year, now.Date.Month,1).AddMonths(0).AddDays(-1).ToString(“yyyy-MM-dd”)”
Hey!
I am getting the output:
First Query:(Dictionary)
Assign output = New datetime(now.Date.Year, now.Date.Month,1).AddMonths(0).AddDays(-1).ToString(“yyyy-MM-dd”)
Second Query:(Output)
Assign DateTime_Var = Datetime.ParseExact(output.ToString, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")
Regards,
NaNi
Rhys18
(Rizky Albert Hartono)
June 30, 2022, 9:53am
13
Rhys18:
I got this error instead… Wasn’t datetime.parseexact converting to datetime var type?
Hi!
Sorry!
Both are string variables only!
Regards,
NaNi
Rhys18
(Rizky Albert Hartono)
June 30, 2022, 10:02am
15
Okay I got it solved
This is my dictionary I modified just now :
I want to make the months to be flexible so I modified the value of the AddMonths from this :
New datetime(now.Date.Year, now.Date.Month,1).AddMonths(0).AddDays(-1).ToString(“yyyy-MM-dd”)
To This :
New datetime(now.Date.Year, now.Date.Month,1).AddMonths(CInt(config_excel("month"))).AddDays(-1).ToString(“yyyy-MM-dd”)
Thank you for trying to help everyone
system
(system)
Closed
July 3, 2022, 10:02am
16
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.