If condition syntax with date

Hi,

I am reading a cell 31/03/2023 which is a date and variable type is generic value. I wan to use a if condition to do a validation where the cell date should be equal or more than 01/04/2023 which executes the then or otherwise the else. How do i script this?

To add on the cell date it reads can be dd/Mm/yyyy or d/m/yyyy.

Hi @mark_rajkumar1

Store the Cell value in a variable called InputValue.

You can give the below expression in If condition to check the condition,

- Condition -> DateTime.ParseExact(InputValue.ToString, {"dd/MM/yyyy","d/M/yyyy"}, System.Globalization.CultureInfo.InvariantCulture, Datetimestyles.None) >= DateTime.ParseExact("01/04/2023", "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)

It will wok weather the cell value is in these formats, dd/MM/yyyy and dd/M/yyyy

Hope it helps!!

Hi @mkankatala, as for 01/04/2023 which i want it be current period. In another words, i wan the script to compare dates with today date.

Okay got it… @mark_rajkumar1

Then use the below condition,

- Condition -> DateTime.ParseExact(Input.ToString, {"dd/MM/yyyy","dd/M/yyyy"}, System.Globalization.CultureInfo.InvariantCulture, Datetimestyles.None) >= DateTime.Now

Hope it helps!!

Hi @mkankatala i wan to set the date as 01-04 fixed and the years shld be moving forward.

@mkankatala for example if cell date is 31/03 2024 and is not greater than 01/04/2024, it will execute else

Could you be more specific. What is your requirement… @mark_rajkumar1

My requirement is i need read cell what contains a date but variable type is generic value. However i want to use that variable to see is it greater than 01/04 which current date and year. If it is greater it had to do this validation or else no validation. If next year or even following year the script should know carry on with the validation with the current period.

@Anil_G any inputs to this

@mark_rajkumar1

Give condition like this

Cdate(GenericValue.Tostring)> Cdate("01/04/" + Now.Year.ToString)

Cheers

Okay @mark_rajkumar1

I modified the condition based on your requirement, check the below one,

- Condition -> DateTime.ParseExact(Input.ToString, {"dd/MM/yyyy","dd/M/yyyy"}, System.Globalization.CultureInfo.InvariantCulture, Datetimestyles.None) >= DateTime.ParseExact("01/04/"+Now.tostring("yyyy"), "dd/MM/yyyy", System.globalization.Cultureinfo.Invariantculture)

Hope it helps!!

@Anil_G i dont wan the time to be shown. The date format has to be shown as dd/Mm/yyyy or d /m/yyyy

@mark_rajkumar1

For comparing in the current date I am not using time and in the generic value I believe you are not getting it

cheers

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