Help needed with getting a Date range

I need to generate a Date of birth that is more than 65 years from Date of run BUT can not be more than 75 years (the age limit).

Currently, my workflow is generating the DOB that are over 65 years (some are even 105 years old) but the business rule needs the DOB to be between 65 and 75 years from date of execution.

I need to implement a logic to ensure that the random dates are between 65 and 75 but I’m having trouble using the BETWEEN clause.

Below is how I’m generating DOB greater than 65.

Error I’m getting when I tired to use the “Between” clause

Attached is my workflow for reference.
DOB_genator.zip (2.9 KB)

Hi @Yomi_Oluwadara

Try the below syntax:

randomDOB = DateTime.Today.AddYears(-65).AddDays(-New Random().Next(0, 365 * 10)).ToString("yyyy-MM-dd")

randomDOB is of DataType System.String

Regards

1 Like

@vrdabberu,

Here is sample workflow.

GetDOB.xaml (8.4 KB)

Output:
image

Thanks,
Ashok :slight_smile:

Thanks to you both

@ashokkarale
What if there is a use case to generate multiple DOBs at the same time. Let say there is an argument (numberOfDOBTogenerate) that specifies the number of DOB between 65 and 75 the user wants, how would you enhance your workflow to do this? Would you out the do-while inside a For loop?

I will appreciate it if you can enhance your workflow to use the variable numberOfDOBTogenerate . so we can generate N number of DOB based on the value the user assign for variable numberOfDOBTogenerate

Thanks!

Hi @Yomi_Oluwadara

Check the below xaml file:
randomDOB = Enumerable.Range(1, CInt(str_Dates)).[Select](Function(i) DateTime.Today.AddYears(-65).AddDays(-New Random().Next(0, 365 * 10)).ToString("yyyy-MM-dd")).Aggregate(Function(current, nextDOB) current & Environment.NewLine & nextDOB)

Based on the number you provide in the Input Dialog that many dates will get printed between 65 and 75.

Sequence14.xaml (8.5 KB)

Regards

@Yomi_Oluwadara,

Updated code to avoid duplicate dates.

Here is improvised solution:

Sample Code:
GetDOB.xaml (11.0 KB)

Output:
image

Thanks,
Ashok :slight_smile:

Thanks @ashokkarale and @vrdabberu

2 Likes

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