cancel
Showing results for 
Search instead for 
Did you mean: 

Flow - Calculate Date Diference

Definition :- ticks(timestamp: string) - Returns the number of ticks (100 nanoseconds interval) since 1 Jan 1601  00:00:00 UT

 

Scenario :-

 

SharePoint list contains following columns:-

 

Title (Single Line of Text)

Contract Executed Date (Date)

 

Capture.PNG

 

 MS Flow :-

 

Get items from list

 

Capture.PNG

 

 

 

 

 

 

 

 

 

 

 

Run Select data operation to calculate number of days between Today's date and the Contract Executed Date

 

 

Capture.PNG

 

 

 

 

 

 

 

 

 

The expression for Days Since Contract Executed :-

div(sub(ticks(formatDateTime(utcNow(),'yyyy-MM-dd')),ticks(item()?['ContractExecutedDate'])),864000000000)
 
ticks(formatDateTime(utcNow(),'yyyy-MM-dd') - Number of Ticks since 1 Jan 1601 and Today's Date
ticks(item()?['ContractExecutedDate']) - Number of Ticks since 1 Jan 1601 and Contract Executed date
sub - subtracting the number of ticks
div - divide the result from 864000000000 (conversion from nanoseconds to days)
 
Output of Select when Flow runs :-
Capture.PNG
 
 
Another use case would be to do date comparisons using Ticks
 
Filter all contracts which have Contract executed date in the last week
 
Capture.PNG
 
ticks(item()?['ContractExecutedDate']) - Number of Ticks since 1 Jan 1601 and Contract Executed date
ticks(formatDateTime(adddays( utcNow(),-7),'yyyy-MM-dd')) - Number of Ticks since 1 Jan 1601 and [Today's Date - 7 ] (in the last week)
 
utcNow() - current date and time
adddays( utcNow(),-7) - adds (-7) days to todays date 
formatDateTime(adddays( utcNow(),-7),'yyyy-MM-dd') - format the date time to date 'yyyy-MM-dd'
 
Check if ticks - Contract Executed date is greater than the ticks  - since Last week
 
Data in Contracts List :-
 
 
Capture.PNG

Flow - Filter using ticks expression
Capture.PNG
 
Flow - Select the filtered operation result and get Tile of contract
 
 
Capture.PNG
 
Result of Flow run for Select -
 
Capture.PNG
 
Only "Contract 2" is returned as it has Contract Executed Date since last week
 
Thanks for reading !!!
Comments

@Mdorrani 

 

Great post, I wonder if you could help with this issue. Your way seems to have less steps.

 

https://powerusers.microsoft.com/t5/Building-Flows/Build-a-Flow-based-on-time-passed-and-Choice-Fiel...

Meet Our Blog Authors
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • SharePoint, Microsoft 365 and Power Platform Developer | Contributor on SharePoint StackExchange
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 12 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/