How to not read excel value as string

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 :slight_smile:

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

Hi, I tried to combine with the solution you give and I got this error instead :

image

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

Hi,

so this is my original code :

image

then there’s a change on the New.Datetime declare need to be stored in dictionary. When I use dictionary I receive this output :

image

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.

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

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

I got this error instead… Wasn’t datetime.parseexact converting to datetime var type?

Hi!

Sorry!

Both are string variables only!

Regards,
NaNi

Okay I got it solved

This is my dictionary I modified just now :

image

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 :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.