How to get the value of last row and add 1 Day on a String Varable(MM/dd/yyyy)?

  1. I want to get the value of the last row in Column A in DT “LastRow”
    so I assign a String Variable “TD” with “LastRow.Rows(LastRow.Rows.Count-1)(0).ToString”
    and it works.
  2. I need to Add 1Day to “TD” (eg. TD=01/06/2021, I need TDD=01/07/2021)
    I assign a String Variable “TDD” with
    “Date.ParseExact(TD,“MM/dd/yyyy”,CultureInfo.InvariantCulture).AddDays(1).ToString(“MM/dd/yyyy”)”
    then it shows error as below
    “Assign: String was not recognized as a valid DateTime.”

How can I to fix it? Please help me~~~Thanks!

Hi @StevenKai

Use below method.

Date.ParseExact(TD,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).AddDays(1).ToString(“MM/dd/yyyy”)

I tried this method and I got the right output.

Try this and let me know

2 Likes

Thanks for help!
But~~the result is the same
“Assign: String was not recognized as a valid DateTime.”

I set the types of both “TD” and “TDD” variable to “String”, is that correct??

Yes, correct.

Check this flow
Main.xaml (4.8 KB)

I knew the difference between our methods.
my “TD” isn’t “01/06/2021” from the beginning.

My “TD” was assigned to get the value of last row in DT. (as my workflow showed above)
As I used “TD” in assign “TDD”, then always showed error!

Hi @StevenKai

While using read range check the preserve format too

It will preserve the date format as mm/dd/yyyy

Other wise date will be outputed as

mm/dd/yyyy hh:mm:ss

Hope it helps you

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

1 Like

Not work~
I checked the preserve format too.
but the error still shows…

Hi @StevenKai

Can u show the output of date in wrriteline ?

Here was the output of workflow
output

Hi @StevenKai,

I am suspecting there is a whitespace in your TD variable read from excel. Try

  • TDD = Date.ParseExact(TD.ToString.Trim,“MM/dd/yyyy”,CultureInfo.InvariantCulture).AddDays(1).ToString(“MM/dd/yyyy”)
2 Likes

Sorry,
Still not work…showed the same error message.

It works fine when I assing your string as a string.
TDD = Date.ParseExact(TD.ToString.Trim,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).AddDays(1).ToString(“MM/dd/yyyy”)

Can you also check your imports in the workflow?

image

Thanks to @ abu.behlim @NIVED_NAMBIAR @jeevith (Sorry for tag only 2 users, because I am new user here XD)
I got the correct output of TDD!!

as @jeevith said, there is a space or other tag in Excel file, when I export from my system.
jeevith’s method is not work finally, but very helpful to remind me to correct the sourcing file.

I assign another TD1 variable with “TD.Substring(0,10)”
then DONE!!

Here is my final workflow

3 Likes

Hi @StevenKai,

Just a heads up, there might be times when your string has unwanted strings before it as well for example if someone manually typed a space before the date string or scrapped values from websites, which can have non ASCII characters. In such cases, the Substring method can lead to issues.

I suggest you find out what the unwanted characters are and remove them or use regex expression to match your date string format that way you know this automation will work even if there are unwanted characters before or after the string.

1 Like

Hi @jeevith,

Thanks for your suggestion, I found that the unwanted characters is due to my company’s information system.
When I export the data from the internal application, it occurs.
I have no power to adjust the coding of the application, so I only can find the easy way to fix my data to fit my workflow. :sweat_smile:
I’ll try about “regex expression”, thanks again!

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