Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

Calculate with today’s date in a SharePoint column without daily updates

Posted on February 21, 2021June 29, 2022 by Tom

“How can I display number of days between today’s date and another date in a SharePoint column without Power Automate daily updates?”


Calculating a number of days between a date and today’s date is not simple in SharePoint. You probably use calculated column for that, but calculated column can’t work with today’s date directly. It offers today() function, but the today() date does not update automatically. It’s updated only when the item is updated, otherwise it keeps the original value. If you don’t update the item for a month, the today() function will keep the same date for a month. That’s not really an acceptable solution.

Other solution is to add another column for today’s date and update the column daily with Power Automate. A scheduled flow that would run daily and update the today’s date for all items. Once you have both the dates in a column, you can easily use them in a calculation. The problem can be the daily updates. All items are updated every day, if you keep version in the list, you’ll get 365 version every year just to update the date. If you’ve got a flow with trigger on item modifications on that list, you must be careful. If users have any alerts on the list, they’ll receive a lots of emails. I’d say there’re too many potential problems with this approach.

Use JSON column formatting

Since the goal is to display a number of days between two dates, you don’t really need a calculated column for the calculation. You can use any column and format it with a JSON to display the result of the calculation. It’s the same approach as when building a calculated hyperlink.

JSON allows you to use @now, a placeholder for today’s date. Unlike the today() function in calculated column formula, @now will give you always today’s date. That allows you to calculate the difference in days between today and the other date. The example below will calculate number of days since the SharePoint item was created (using the Created column with the [$Created] placeholder).

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=floor((Number(@now)-Number([$Created]))/(1000*60*60*24))"
}
SharePoint calculation using today's date and another date column

Image note: ‘Calculated’ column is using the today() function. ‘New column’ is a Single line of text column with the JSON formatting. The screenshot is from February 21, 2021.

To break down the calculation into pieces:

  • Number(…) will convert a date into a number in milliseconds
  • Number(@now)-Number([$Created]) will take today’s date in milliseconds and subtract from it Created date in milliseconds
  • (1000*60*60*24) will calculate duration of a day in milliseconds: 1000 milliseconds * 60 seconds * 60 minutes * 24 hours
  • floor((Number(@now)-Number([$Created]))/(1000*60*60*24)) will take the difference between dates, divide it by duration of a day, and round the final number down to a full number

You can use this formatting on any SharePoint column. It’ll suppress the value in the column and display the result of the calculation instead.

Summary

I consider JSON formatting on SharePoint column a much better replacement for Calculated columns. It gives you so many possibilities to change the looks and functionality on the SP views, just take a look on the Microsoft article.

It allows you to do calculations as shown in this post, you can use it to build hyperlinks, hide empty links, and much more.

I should just mention that JSON formatting will work only in Modern SP. If you’re still using Classic SP you might need to switch it, but you’ll do it anyway sometime in the future, why not now.

And to move the functionality one step further, you could add also a reminder flow.

UPDATE: there’s now also a post dedicated to formatting the result.


🚀 Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

56 thoughts on “Calculate with today’s date in a SharePoint column without daily updates”

  1. Mike says:
    February 22, 2021 at 11:37 am

    Very useful post Tom thank you. Can you apply additional conditional formatting (e.g. severity colors) to what is now essential just a display value rather than an actual field value?

    Reply
    1. Tom says:
      February 22, 2021 at 6:48 pm

      Hello Mike,
      yes, you can, but since it’s just a display value you should use the same calculation in the condition, e.g. to use red color for date difference bigger than 10:

      {
       "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
       "elmType": "div",
       "txtContent": "=floor((Number(@now)-Number([$Created]))/(1000*60*60*24))",
       "style": {
        "color": "=if(floor((Number(@now)-Number([$Created]))/(1000*60*60*24)) > 10, '#ff0000', '')"
       }
      }

      Reply
  2. Kent says:
    April 24, 2021 at 11:40 am

    Thanks for the guidance! It works well in sharepoint. However, with Power Automate (Select > Create html Table > Compose), the display value (day difference) does not show up in email. In othter words, the display value (day difference) will be having missing field in email. Are you able to advise?

    Reply
    1. Tom says:
      April 26, 2021 at 9:03 am

      Hello Kent,
      JSON column formatting is on user side only (calculated in the browser), the value is not stored in the list and therefore can’t be used in the flow. To use the value in a flow you’ll need to recreate the calculation. The expression below will calculate the difference between today and a date in a flow, don’t forget to replace the whole placeholder [dateDynamicContent] with your date.
      div(sub(ticks(utcNow()),ticks([dateDynamicContent]),864000000000)

      Reply
  3. Kent says:
    April 27, 2021 at 2:51 am

    Thanks Tom for the prompt response! I applied the expression above and it will be generating the day difference in Apply To Each (for each row item in Sharepoint). Next. how am i going to insert the output (day difference generated by Apply To Each) in Map in Select operation?

    I attempted with Append to String/Array Variable but it does not work. It will display 1511 /[15,1,1] respectively. The output is lumped together instead. Sidenote: first, second and third day difference is 15, 1 and 1 day respectively.

    Reply
    1. Tom says:
      April 27, 2021 at 3:06 pm

      Hello Kent,
      you don’t need any preprocessing, use the expression directly in the ‘Select’ action. Enter it into the right column in the same way as you’d enter any other dynamic content coming from SharePoint.

      Reply
  4. Kent says:
    April 28, 2021 at 11:15 am

    Tom, it works well indeed! I appreciate your guidance to clear up my doubt! Thanks again!

    Reply
  5. Mauro says:
    May 6, 2021 at 3:19 pm

    Hi, thanks for the info! I only need the column to display today’s date with hours, minutes and second and, without substracting anything. I used your Json but I took out the whole formula except @now, is there another expression to get the date without the time? Thanks!

    Reply
  6. Mauro says:
    May 6, 2021 at 3:26 pm

    sorry I meant:
    “… I only need the column to display today’s date WITHOUT hours, minutes and second and, without substracting anything…”

    Reply
    1. Tom says:
      May 10, 2021 at 9:31 pm

      Hello Mauro,
      I think that the easiest way would be to use toLocaleDateString(…) function:
      “txtContent”: “=toLocaleDateString(@now)”

      Reply
  7. Jean-luc Hornsby says:
    May 13, 2021 at 11:48 am

    Hi this code works great, I was wondering if I would be able to calculate the days to go, based upon the expiry date (date field) minus [today] rather than date created minus [today]?
    Thank you

    Reply
    1. Tom says:
      May 18, 2021 at 1:33 pm

      Hello Jean-Luc,
      you can access the expiry date date in the same way as the created date [$Created], just replace the ‘Created’ with the other column name.

      Reply
  8. Christine Green says:
    May 19, 2021 at 3:45 pm

    Is there any way to sort the “New Column”? Because it’s a text field, the normal numerical sorting isn’t working. Filter doesn’t work either. Hoping there is a workaround – thanks!

    Reply
    1. Tom says:
      May 20, 2021 at 6:39 pm

      Hello Christine,
      you can’t sort by the values calculated in the JSON column, the calculation takes place in user’s browser and it’s only shown to the user, it’s not stored in the list.

      Reply
  9. Ali says:
    June 20, 2021 at 5:53 pm

    Hi, how do I retrieve data from that column?

    Reply
    1. Tom says:
      June 23, 2021 at 9:36 am

      Hello Ali,
      you can’t, the calculations is done in the browser, not directly in SharePoint. If you need the information somewhere else, you’ll need to repeat the same calculation, e.g. if you’re sending the data in an email, you must recalculate it when building the email.

      Reply
  10. Joe says:
    June 28, 2021 at 4:32 pm

    Hi Tom,

    Thanks for this post and helping a eager learner.

    I want to add an if statement to this calculation. I tried this JSON, but it only displays the JSON text and does not show a number. Any help would be appreciated.

    {
    “$schema”: “https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json”,
    “elmType”: “div”,
    “txtContent”: “=if([$Status]=’In Process’,floor((Number(@now)-Number([$Date_x0020_Held]))/(1000*60*60*24)),floor((Number([$Date_x0020_Resolved])-Number([$Date_x0020_Held]))/(1000*60*60*24))”
    }

    Reply
    1. Tom says:
      June 29, 2021 at 9:41 am

      Hello Joe,
      the ‘is equal’ condition is represented by 2x =, try to add the second one.
      [$Status]=='In Process'

      Reply
  11. Joe says:
    June 29, 2021 at 11:13 pm

    That worked!

    Reply
  12. Megan says:
    July 15, 2021 at 2:29 am

    Can you please show how you would use div(sub(ticks(utcNow()),ticks([dateDynamicContent]),864000000000)
    in an action in a Flow? I want to send a reminder based on the modified date of the list item. I have used JSON to show the days since item was last modified in my SP list. Every 3 months I want to send the assignee of the list item an email notification if the item has not been modified for x amount of days.
    Thanks!

    Reply
    1. Tom says:
      July 21, 2021 at 11:24 am

      Hello Megan,
      you just have to replace the [dateDynamicContent] part with the dynamic content that represents the Modified date, e.g.div(sub(ticks(utcNow()),ticks(items('Apply_to_each')?['Modified'])),864000000000).

      Reply
  13. ismail says:
    August 11, 2021 at 11:47 am

    hi tom, what formula should we use, and after that should we add this json formula to make this automated?

    Reply
    1. Tom says:
      August 12, 2021 at 10:34 am

      Hello ismail,
      I’m sorry but I don’t understand the question, what are you trying to achieve? The whole json including the formula is in the code snippet.

      Reply
  14. Mark Curtin says:
    August 11, 2021 at 8:58 pm

    Thank for very much for posting this. I followed your approach though and each row is returning the value 18850 in the column where I applied your code. Any thoughts on why that is, what I am doing wrong. Thank you. Mark

    Reply
  15. Mark Curtin says:
    August 11, 2021 at 10:04 pm

    Never mind, I think i wasn’t inputting the reference field name correctly. Another question. Is it possible to then add more JSON to have a data bar associated with these value?

    Reply
    1. Tom says:
      August 12, 2021 at 10:37 am

      Hello Mark,
      you can add a style to the JSON as shown in the 2nd comment, but since the value is calculated on the client side, you must repeat the whole calculation also in the style section, e.g.
      "style": {
      "color": "=if(floor((Number(@now)-Number([$Created]))/(1000*60*60*24)) > 10, '#ff0000', '')"
      }

      Reply
  16. ismail says:
    August 13, 2021 at 10:32 am

    i have the same problem and i don’t know how to fix it

    Reply
  17. ismail bakraoui says:
    August 13, 2021 at 10:49 am

    hi tom, I am working on this employee list and i have added this column that contains today’s date so it would be easier for me to calculate when an employee started working and when his contract ends, by using power automate the goal is to be sent an email when an employee’s contract is about to finish, problem is that it says flow ran successfully but expression in my condition is false and i don’t receive any emails, any suggestions?

    Reply
    1. Tom says:
      August 14, 2021 at 7:49 pm

      Hello ismail,
      the number of days is calculated only in the browser, it’s not stored in the item itself. To send a reminder you must do the whole calculation again in the flow, there’s already a post on how to do this.

      Reply
  18. Christoph says:
    March 4, 2022 at 12:51 pm

    Hi Tom,

    that is a very helpful one. I just added it to one of my lists. One addition I would like (but failed to implement: Only show positive values.

    I compare today to a future date and once that day has come, I Don´t want to have negative numbers in my list, just a blank. I tried some “if” magic, but all failed. What´s the smartest way to d this?

    Reply
    1. Tom says:
      March 5, 2022 at 7:23 pm

      Hello Christoph,
      you can add the “display” property into “style” in the same way as in this post: https://tomriha.com/hide-json-built-hyperlink-in-sharepoint-list-if-theres-no-underlying-link/
      "style": {
      "display": "=if(floor((Number(@now)-Number([$Created]))/(1000*60*60*24)) < 0, 'none', 'inherit')" }

      Reply
  19. Christoph says:
    March 18, 2022 at 11:37 pm

    Great! Thanks, Tom!

    Reply
  20. Mike1 says:
    March 21, 2022 at 10:08 pm

    I keep getting the same value 19072 for each row? I confirmed my date column ($Calculated) was keyed correctly.

    {
    “$schema”: “https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json”,
    “elmType”: “div”,
    “txtContent”: “=floor((Number(@now)-Number([$Calculated]))/(1000*60*60*24))”

    Reply
    1. Tom says:
      March 29, 2022 at 11:16 am

      Hello Mike,
      isn’t the $Calculated a calculated field? I’m not sure if it’ll work as the whole solution is designed to replace calculated fields.

      Reply
  21. Lauri says:
    June 13, 2022 at 6:26 pm

    This JSON:

    { “$schema”: https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json, “elmType”: “div”, “txtContent”: “=floor((Number(@now)-Number([$Created]))/(1000*60*60*24))” }

    But instead of Created date, in my SharePoint List, the column to compare to is: Calibration expiration date

    I tried this:

    { “$schema”: https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json, “elmType”: “div”, “txtContent”: “=floor((Number(@now)-Number([$Calibration expiration date]))/(1000*60*60*24))” }

    But it just displays the JSON. I’m sure it’s something simple I am missing… Would you mind letting me know? Thank you, btw, for this and all your other very helpful articles!

    Reply
    1. Tom says:
      June 19, 2022 at 10:10 am

      Hello Lauri,
      you must use the column internal name – no spaces, no special characters (https://tomriha.com/what-is-sharepoint-column-internal-name-and-where-to-find-it/)

      Reply
  22. S says:
    June 14, 2022 at 3:29 pm

    Hi Tom – do you know how to do this when ref to another column that has the date in? So, expected outcome would be – if date in col X is over 365 past, then red bg, else green bg (and text saying “blank date” if col X doesn’t have a date populated?)

    Reply
    1. Tom says:
      June 19, 2022 at 7:35 pm

      Hello S,
      all the columns are referenced by their internal name, e.g. [$CustomDateColumn], so just use this syntax to include other columns in the formula(s).

      Reply
  23. Tammy says:
    June 16, 2022 at 3:53 pm

    Hi Tom –
    I think I am not using the correct syntax for the date field I want to use (Referral Date). When I test using [$Create], I get a valid number of days, but when I switch to use [$Referral Date], I get the JSON statement in my column. Here is my JSON. What am I missing?
    {“$schema”:”https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json”,”elmType”:”div”,”txtContent”:”=floor((Number(@now)-Number([$Referral Date]))/(1000*60*60*24))”}
    Thank you

    Reply
    1. Tom says:
      June 22, 2022 at 8:58 pm

      Hello Tammy,
      you must always use the column internal name – no spaces, no special characters, etc.: https://tomriha.com/what-is-sharepoint-column-internal-name-and-where-to-find-it/

      Reply
  24. France says:
    June 17, 2022 at 2:10 pm

    Hi Tom, are you able to use the above formula to calculate business/working days? Not all days between ‘today’ and the created date?
    And, how would I format the age to show as ‘sp-css-color-CoralFont’ with the background ‘sp-css-backgroundColor-BgCoral’
    Like the sharepoint formatting default options allow you to show the field as a fully coloured in box, with the font
    I tried to look at their JSON for it… but I got totally lost as to which part I should include and where…

    Reply
    1. Tom says:
      June 22, 2022 at 9:14 pm

      Hello France,
      that would be a hell of a JSON to calculate also with business/working days, I’m not sure anyone would be willing to spend the time to create it (if it’s even possible).
      If you want to use classes in the JSON then it must be in the “attributes” element, as shown in the example here: https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#conditional-formatting-based-on-a-number-range-basic
      For example:
      {
      “$schema”: “https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json”,
      “elmType”: “div”,
      “txtContent”: “=floor((Number(@now)-Number([$Created]))/(1000*60*60*24))”,
      “attributes”: {
      “class”: “=if(floor((Number(@now)-Number([$Created]))/(1000*60*60*24)) > 1, ‘sp-css-backgroundColor-BgCoral sp-css-color-CoralFont’, ”)”
      }
      }

      Reply
  25. Heather says:
    June 23, 2022 at 1:17 am

    In Sharepoint, I want to have 2 columns, one with an expired date and the other a status column active or expired( default active). When a contract expires, let’s use today’s date, I want the status column to change to expired. Does anyone have a suggestion for a JSON formula? It seems pretty easy, but I am not sure what to use. Today I have to use a report to see which ones have expired and change the status manually and do not want to do that any longer.

    Reply
    1. Tom says:
      June 29, 2022 at 6:03 pm

      Hello Heather,
      JSON formatting is used only to display data in some format, it doesn’t update anything on the background. If you want to change status in another column then you’ll need a flow similar to a reminder: https://tomriha.com/how-to-build-basic-reminder-flow-using-power-automate-and-sharepoint/. ‘Get items’ where the date is equal to today and update their status.

      Reply
  26. Pedro says:
    July 26, 2022 at 11:16 am

    Hi Tom, excelent post, thanks for sharing, I have a question, how could you express the result in days & hours format?

    Reply
    1. Tom says:
      August 1, 2022 at 7:37 pm

      Hello Pedro,
      you probably could do that, but but the JSON will be quite complicated, you’d have to calculate hours instead of days, divide it by 24 to get the number of days and then modulo by 24 to get the remaining number of hours.

      Reply
  27. Mayur says:
    November 10, 2022 at 5:17 pm

    Hi Tom,
    This post is a life saver for me. Although, could you suggest how to make sure this date difference value is also populated in excel export? I am simply exporting the list to excel, but the value doesn’t appear. I am not using power automate.

    Reply
    1. Tom says:
      November 13, 2022 at 6:49 pm

      Hello Mayur,
      to get the value into Excel you’ll have to do the calculation somewhere before/during the export and store the values, this solution is to “view only”.

      Reply
  28. Petermichael says:
    December 13, 2022 at 9:24 pm

    Thanks for the share, Tom.
    I had JSON code showing up until I used the internal column name.
    Now that I corrected that, I now have nothing showing in the column.
    Any ideas?

    The type of information in this column is:
    Number (1, 1.0, 100)

    Require that this column contains information:
    No
    Enforce unique values:
    No

    Number of decimal places:
    Automatic

    Default value:
    Number
    _____________________________________________
    {
    “$schema”: “https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json”,
    “elmType”: “div”,
    “txtContent”: “=floor((Number(@now)-Number([Event_x0020_Date]))/(1000*60*60*24))”
    }
    _____________________________________________

    Reply
    1. Petermichael says:
      December 13, 2022 at 9:58 pm

      The $ was lacking.
      Thanks again for sharing!

      Reply
  29. Swati says:
    March 15, 2023 at 10:44 am

    Hi All,

    This is really useful information, however I need to highlight entire based nested conditions, like >30 and <180 – amber, <30 red and others green.
    can anyone please help.

    Regards,
    Swati

    Reply
    1. Tom says:
      March 25, 2023 at 8:26 pm

      Hello Swati,
      like this: https://tomriha.com/how-to-highlight-whole-sharepoint-row-based-on-calculated-date/

      Reply
  30. swati says:
    March 15, 2023 at 10:45 am

    Entire Row*

    Reply
  31. stephen pineda says:
    September 4, 2023 at 4:46 am

    Good day how will i customize it where in i want it to be hours diff. instead of days?

    Reply
    1. Tom says:
      September 10, 2023 at 3:17 pm

      Hello Stephen,
      just divide it with a different number, I put a table here: https://tomriha.com/how-to-calculate-difference-between-two-times-in-power-automate/

      Reply
  32. Marco Alvarado Vargas says:
    July 24, 2024 at 1:35 am

    Hi Tom.

    Very useful post thank you.

    Quick question: Is there a way to get the workday difference from Monday to Friday? Right now, it is counting all days, but I need to count only workdays.

    Regards,

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

🚀 Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Working on an Approval process?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy a fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundle—everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes