web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Random date input not ...
Power Automate
Answered

Random date input not creating dates in December

(0) ShareShare
ReportReport
Posted on by 27
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
Categories:
I have the same question (0)
  • Chriddle Profile Picture
    8,443 Super User 2025 Season 2 on at
    13 ;)
     
  • Expiscornovus Profile Picture
    33,195 Most Valuable Professional on at
     
    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
     
     
     
  • Verified answer
    Chriddle Profile Picture
    8,443 Super User 2025 Season 2 on at
    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'
    )
     
  • chris9486 Profile Picture
    27 on at
    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.
  • Expiscornovus Profile Picture
    33,195 Most Valuable Professional on at
    Nice job @Chriddle, single expression is even better 
  • chris9486 Profile Picture
    27 on at
    I have several questions after testing these methods this morning.
     
    Context; at work I am making an access register for shared files. SharePoint list has 1015 items on but we don't know when we shared them with the individuals. We want to check every XX days whether they need access. So we're wanting to generate random dates within a 6 month period to fill in the access granted date column- spaced out so we don't get overloaded each day with ones we need to check.
     
    @Chriddle - I can't get your method to work with dates in the past. What changes would I need to make to the expression to choose between a date in the past and future (say 01/10/2024 - 01/04/2024). It's 10:14am now and I have been at this since 6.30am.
     
    @Expiscornovus - your method is working almost perfectly. I put the start date as 2024/10/01 and end date as 2025/04/01.  It is writing dates in September. It's driving me up the wall because no where am I stating to start in September. So I don't know why it is doing it. 
     
     
  • Chriddle Profile Picture
    8,443 Super User 2025 Season 2 on at
    Just replace utcNow() with the date. If your date doesn't have a time, the function startOfDay() is not needed.
     
    E.g.
    addDays(
    	'2023-01-01',
    	rand(
    		0,
    		int(
    			first(
    				split(
    					dateDifference(
    						'2023-01-01',
    						'2025-01-01'
    					),
    					'.'
    				)
    			)
    		)
    	),
    	'yyyy-MM-dd'
    )
     
  • chris9486 Profile Picture
    27 on at
    @Chriddle thank you for the quick reply. That works. I thought it was doing September again, but I figured it out. I am going to blame it on my lack of sleep. When I was clearing the date column using PA and then using the expressions/composes to fill in the date, I didn't have 5000 written in my get items top count so it was only doing the default 100. So when I was asking it to clear the column it was only doing the first 100. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard