Date format issue in Studio

I’m on Studio.
I’ve an spreadsheet that has 2 columns with date. I’m comparing the ‘Issued Date’ column with Today’s date.
Here’s what I’m doing - Read the file into DT. In the For loop DT, I do as Assign
MyInvDate = DateTime.ParseExact(CurrentRow.Item(“Issued Date”).ToString, “MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)

(MyInDate is of DateTime type)

In the If statement, I write MyInvDate >= DateTime.Today and Write Line MyInvDate.ToString

It shows error - String is not recognized as a valid date format.


MyInvDate = DateTime.ParseExact(CurrentRow.Item(“Issued Date”).ToString, “M/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
Format is M/dd/yyyy not MM/dd/yyyy

@Eric_Wong_Test … used M as you said but still seeing that error.

@Prinal_C - Please try this…

DateTime.ParseExact(CurrentRow.Item(“Issued Date”).ToString, “M/dd/yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)

@prasath17 … thank u! this works but my input is without that time part “HH:mm:ss”. How to get rid of it ?

@Prinal_C - you don’t have to get rid of it…Even though when you see you don’t have time values but in the backend, excel dates has time values attached to it.

If you want to get rid of it, you have to try using “Preserve format” in the read range.

But please keep in mind that DateTime.Today also prints like this only “04/29/2021 00:00:00”…

1 Like

@prasath … i’ve kept is with the time part. Now in the If statement, I do
MyInvDate >= DateTime.Now but it only shows 4/30/2021 and does not show 4/29/2021

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