Help with DateTime compiler error

My goal is to generate random dates that are older then 65 years from time of run. I was using the Datetime function but I’m getting an unexpected error.

Here is my code
Screenshot_2

Here is my error
Screenshot_1

here is my little workflow
DOB_genator.zip (2.2 KB)

Hello

How about replacing 365 * 65 with 23725

Next(0,23725)

Or

Can you try breaking down the steps into multiple assigns.

Start with the 365 * 65 step first as the error mentions ‘Next’

Hopefully this helps

Cheers

Steve

@Steven_McKeering Thanks, I tried breaking it down, but still getting that error on Next. From the docs I have read, it should work just fine. I must be missing something

Hello

Try this:
image

Assign 1
image

Assign 2
image

Result
image

Hopefully this helps,

Cheers

Steve

Back again

Yep you can achieve in one assign.

Try the syntax like this,

image

image

Cheers

Steve

@Steven_McKeering Thanks the single syntax using a new Random object fixed the compile error.
However, my output, the date ( which should be DOB older than 65 years old) is not accurate. its returning dates that are not older than 65 years old.

RHS of Assign

full assign
image

inaccurate outputs
image
image
image

Missed a minus…

Try this:
DateTime.Today.AddYears(-65).AddDays(-(new Random().Next(1,23725))).ToString(“yyyy-MM-dd”)

image
image

Hi @Yomi_Oluwadara

Try this:
DateTime.Today.AddYears(-65).AddDays(-New Random().Next(0, 365 * 65)).ToString("yyyy-MM-dd")

Regards

1 Like

@vrdabberu and @Steven_McKeering Both variations worked! I can only mark one as the solution. but THANK YOU BOTH very much.

2 Likes

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