How to verify if a date falls in a specified range?

Hi Community,

How to verify if a particular date falls between start date and end date.
Ex. Verify 7/26/2024 is between 07/30/2023 and 07/27/2024
.

I have tried using if condition as shown below:
Convert.ToDateTime(ExpectedBookDate) > Convert.ToDateTime(Startdate.ToString).ToString(“MM/dd/yyyy”) AND Convert.ToDateTime(ExpectedBookDate) < Convert.ToDateTime(Enddate.ToString).ToString(“MM/dd/yyyy”)

It’s throwing error whether ExpectedBookDate is of type String or DateTime

BC30512: Option Strict On disallows implicit conversions from ‘String’ to ‘Date’. The selected value is incompatible with the property type.

Please help me with the logic. I’m using 2023 version

Hi @Vaishnav_Tej

Check below post for your reference

Hope this may help you

Thanks,
Srini

Hi @Vaishnav_Tej

Please try this

DateTime.ParseExact(ExpectedBookDate, "MM/dd/yyyy", CultureInfo.InvariantCulture) >= Startdate AndAlso DateTime.ParseExact(ExpectedBookDate, "MM/dd/yyyy", CultureInfo.InvariantCulture) <= Enddate

Hope this helps!!

Hi @Vaishnav_Tej

ExpectedBookDate = "7/26/2024"
StartDate = "07/30/2023"
EndDate = "07/27/2024"

expectedDate = DateTime.ParseExact(ExpectedBookDate, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture)
startDateObj = DateTime.ParseExact(StartDate, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
endDateObj = DateTime.ParseExact(EndDate, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)

If expectedDate >= startDateObj AndAlso expectedDate <= endDateObj Then
    ' The ExpectedBookDate falls between StartDate and EndDate
    ' Do something here
Else
    ' The ExpectedBookDate does not fall between StartDate and EndDate
    ' Do something else here
End If

Note: ExpectedBookDate, StartDate, EndDate are of DataType System.String. expectedDate, startDateObj, endDateObj is of DataType System.DateTime.

Hope it helps!!

Hi

I’m getting this error :
BC30451: ‘CultureInfo’ is not declared. It may be inaccessible due to its protection level. Variable ‘CultureInfo’ is missing. Please use Data Manager to recreate it.

@Vaishnav_Tej

In that case try this

System.Globalization.CultureInfo.InvariantCulture

use this

DateTime.ParseExact(stTest,"dd/MM/yyyy",system.Globalization.CultureInfo.InvariantCulture)

Thanks,

Hi

I’m getting this error :

image

@Vaishnav_Tej

Try this syntax:

expectedDate= DateTime.ParseExact(ExpectedBookDate, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)

Still same error. do I need to download any package?

@Vaishnav_Tej

If(CDate(ExpectedBookDate)>CDate(startdate) And CDate(ExpectedBookDate)<CDate(Enddate),“T”,“F”)

Hi What should be the variables data type?

@Vaishnav_Tej

expectedDate is an DateTime variable. Make sure you have given the datatype System.DateTime.

Regards,

Yes I have given as you mentioned

Hi
I’m getting this error

If: Conversion from string “” to type ‘Date’ is not valid.

I have given this condition in the IF Activity

CDate(ExpectedBookDate)>CDate(startdate) And CDate(ExpectedBookDate)<CDate(Enddate)

try as below
CDate(cstr(ExpectedBookDate))>CDate(cstr(startdate)) And CDate(cstr(ExpectedBookDate))<CDate(cstr(Enddate))

Not Needed @Vaishnav_Tej

It’s working fine at my end.

Regards,

No errors but it’s going to Else part

image

Sequence: Can not assign ‘DateTime.ParseExact(ExpectedBookDate, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture)’ to ‘expectedDate’.

I’m getting these error.

Can you send the workflow

@Vaishnav_Tej

Sequence13.xaml (10.9 KB)

Hope it helps!!