# DateDiff Help for a Newbie

**URL:** <https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719>\
**Category:** Ignition\
**Tags:** reporting\
**Created:** [January 24, 2024, 5:49pm UTC](https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719 "2024-01-24T17:49:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [January 24, 2024, 5:49pm UTC](https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719/1 "2024-01-24T17:49:53Z")

</div>

What is wrong with this syntax...(I'm new)

I am working in a Perspective Report trying to di a date difference as a parameter. It would be calculated based on the StartDate/EndDate inputs that i have above.

If this is not proper then what do i need to do in the script below to reference the StartDate/EndDate parameters to give me the difference between them in hours.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/2/8293defef886627b206c0accd819ec997989e99a.png)

I get this error and it doesn't make sense.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/5/b5f6b9280bffbeadd9f3d36efc4e09afa5552e61.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 24, 2024, 5:56pm UTC](https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719/2 "2024-01-24T17:56:57Z")

</div>

What's the default value you've entered for `StartDate`?

---

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [January 24, 2024, 5:58pm UTC](https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719/3 "2024-01-24T17:58:01Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f59b9c6a2a737fc30f81b453055882d5ec4d3b5d.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/2/22878566f31269506c54292e5b3a98ca0394b629.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 24, 2024, 5:59pm UTC](https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719/4 "2024-01-24T17:59:20Z")

</div>

Tip: your report (and hence your question) have nothing to do with Perspective. The reporting module is separate from both Vision and Perspective. I'll fix the tags for you.

Regarding the error it's telling you that the first argument, {StartDate}, is null so you need to figure out why.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 24, 2024, 6:02pm UTC](https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719/5 "2024-01-24T18:02:08Z")

</div>

You've provided expressions for StartDate and EndDate that produces strings. The parameters are set to the Date datatype. Fix this first. (Don't use strings for dates.)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 24, 2024, 6:02pm UTC](https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719/6 "2024-01-24T18:02:11Z")

</div>

A couple of problems:  
You have set the Parameter Type to Date but the calculated value is a string. That won't work. Remove the dateFormat function.  
Same with EndDate.

The Expression Language **dateDiff** function is expecting dates, not strings.

---

<div class="post-metadata">

**Author:** ![Ben\_Blaschuk](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Ben\_Blaschuk](https://forum.inductiveautomation.com/u/Ben_Blaschuk)\
**Post date:** [January 24, 2024, 8:52pm UTC](https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719/7 "2024-01-24T20:52:55Z")

</div>

I am unable to remove the string format as it is used in a previously made SQL stored procedure that I cannot change. There is a way around it with the date parcing thing I have looked up but it is messy. I think I have a work around for now. It too is messy but simpler I think. Thanks

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 24, 2024, 9:05pm UTC](https://forum.inductiveautomation.com/t/datediff-help-for-a-newbie/84719/8 "2024-01-24T21:05:25Z")

</div>

1. Pass the dates **into the report** as Date data types. Then you can calculate the dateDiff.
2. Format the dates **when you pass them** to the stored procedure if it requires the date in string format.

Note and learn well: dates should be saved as date datatype in the database. Whoever set it up shouldn't have done that. Work with the date datatype and only format dates at the last moment to display for human consumption.
