Skip to main content

Notifications

Power Automate - Building Flows
Answered

Random date input not creating dates in December

Posted on 26 Nov 2024 13:35:51 by 17
I've written an expression that will write random dates but it is completely skipping December. Can someone tell me what I've done wrong please?
 
parseDateTime(concat(concat(concat(concat(rand(9,12),'-'),rand(1,31)),'-'),rand(2024,2024)),'MM-dd-yyyy')
 
If someone could also help me wrote an expression that will write dates into Jan and Feb 2025 that would be great. When I change 2024,2024 to 2024, 2025 and 9,12 to 9,3 it just doesn't work for me.
 
Thank you
  • Expiscornovus Profile Picture
    Expiscornovus 30,548 on 26 Nov 2024 at 14:35:14
    Random date input not creating dates in December
    Nice job @Chriddle, single expression is even better 
  • chris9486 Profile Picture
    chris9486 17 on 26 Nov 2024 at 14:30:26
    Random date input not creating dates in December
    That's brilliant thank you all. Now how do I set all 3 to the answer!!
     
    You've saved me so so so much time.
  • Verified answer
    Chriddle Profile Picture
    Chriddle 6,991 on 26 Nov 2024 at 14:20:33
    Random date input not creating dates in December
    This returns a random date between today (inclusive) and 2025-03-01 (exclusive).
    This only works if the end date is greater than the start date.
     
    addDays(
    	utcNow(),
    	rand(
    		0,
    		int(
    			first(
    				split(
    					dateDifference(
    						startOfDay(utcNow()),
    						'2025-03-01'
    					),
    					'.'
    				)
    			)
    		)
    	),
    	'yyyy-MM-dd'
    )
     
  • Expiscornovus Profile Picture
    Expiscornovus 30,548 on 26 Nov 2024 at 14:18:09
    Random date input not creating dates in December
     
    You can use the Select approach which Paul Murana shared earlier in one of his blogs:
     
    I have tweaked it a bit so it uses a StartDate and EndDate instead. 
     
    Below is an example
     
    From
    range(0,int(first(split(dateDifference(outputs('StartDate'),outputs('EndDate')), '.'))))
     
    Map (switched to text mode)
    formatDateTime(addDays(outputs('StartDate'),item()), 'yyyy-MM-dd')
     
    Compose to pick a random data of that array
    body('Select')[rand(0,sub(length(body('Select')),1))]
     
     
    Test result
     
     
     
  • Chriddle Profile Picture
    Chriddle 6,991 on 26 Nov 2024 at 14:05:07
    Random date input not creating dates in December
    13 ;)
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,129

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,797

Leaderboard