Check the range of Date if falls within fifteen days with the other date

Hi ,

I have two dates :slight_smile:
Say date1 β€œ9/23/2024” and date2 β€œ9/20/2024”

I need to check whether dt1 falls within fifteen days of date1 or prior to that

What will be the expression

@dutta.marina

you can use Cdate(dt2) <= Cdate(dt1).Adddays(15)

cheers

@Anil_G

I thought we need to use something like though I was getting error

DateDiff(dateinterval.Day,str_startdate,cdate(str_signdate)).ToString

@dutta.marina

You can use that as well but both should be suprrounded by cdate and no need of .tostring thwn we need to check if differenceis positive and lessthan 15

Cheers

Hi,
Try using these package it may work β€œFeatSystems.DateTime.Activities”

Are you looking for:

  • Less than or equal to 15 days, e.g 9/20/2024 and 9/23/2024
  • More than or equal to 15 days, e.g. 9/5/2024 and 9/23/2024
  • Less than 15 days
  • More than 15 days

@sudster

Within fifteen days range

  • Less than or equal to 15 days, e.g 9/20/2024 and 9/23/2024

@Anil_G 's answer should work then, or do you need a more elaborate and foolproof solution?

@Anil_G

Is it something DateDiff(dateinterval.Day,cdate(str_startdate),cdate(str_signdate))

image

@dutta.marina

please show the error

cheers

@Anil_G

image

@dutta.marina

use .tostring at the end

cheers

@Anil_G

I am getting as -26 for this condition. If I need to put in If condition and check

just need to see <=15 .need to omit the sign?

for example start_date<=15 ?

Does signing or starting happen first?

@dutta.marina

You can do math.abs(cdbl(yourvariable))

Cheers

@sudster

sign date happens first.after that start date

@sudster

any other method we can do?

to check if a particular date falls within a range of 15 days from the other date

Then you have it reverse here:

Import this namespace, if it is not there:
image

image

DateSigned = DateTime.ParseExact(strSignedDate, "M/d/yyyy", CultureInfo.InvariantCulture)
DateStarted = DateTime.ParseExact(strStartedDate, "M/d/yyyy", CultureInfo.InvariantCulture)
dblDateDiff = DateAndTime.DateDiff(DateInterval.Day, DateSigned, DateStarted)

If Condition:
dblDateDiff > 0 AndAlso dblDateDiff <= 15

Then:
$"Date difference is OK: {dblDateDiff}"

Else:
$"Date difference is NOT OK: {dblDateDiff}"
1 Like

@sudster

dblDateDiff this variable is of type double?