Steven Hargett
Steven Hargett

Reputation: 1

SP2013 get time difference in minutes

I have a list with a date-time column called "Status Date". What I need to do is display the number of hours and minutes between "Status Date" and Now() in a calculated column. The CONCATENATE method does not work, because it only updates when the list item is edited. I need the time difference to update each time the page loads. I am using the workaround to leverage javascript in an tag. However, when I try to use the "Status Date" field in a new Date() method it returns as "Wed Dec 31 19:00:43 EST 1969" here is my code for the calculated column. It returns the number of minutes in the current hour.

<img src='/_layouts/images/blank.gif' onload=""{var startTime=new Date("&[Status Date]&");var endTime=new Date();var difference=endTime.getTime()-startTime.getTime();var rawMins=1000*Math.round(difference/1000);mins= new Date(rawMins);this.parentNode.innerHTML= 'Minutes: '+ mins.getUTCMinutes() ;}"">

Upvotes: 0

Views: 34

Answers (1)

Lee
Lee

Reputation: 5493

Use JSLink for this requirement.

Similar thread here

<script type="text/javascript">
        (function () {
            'use strict';

            var CustomReminder = {};

            /**
             * Initialization
             */
            function init() {

                CustomReminder.Templates = {};

                CustomReminder.Templates.Fields = {
                    'Reminder': {
                        'View': customDTDisplay
                    }
                };

                // Register the custom template
                SPClientTemplates.TemplateManager.RegisterTemplateOverrides(CustomReminder);
            }
            function customDTDisplay(ctx) {                
                //from the context get the current item and it's value
                if (ctx != null && ctx.CurrentItem != null) {
                    //your render logic                    
                }               
            }          

            // Run our intiialization
            init();

        })();
    </script>

Upvotes: 0

Related Questions