Report History Question

Morning,

I am creating a report that pulls from a tag that has history. I want the start date to be 4:00 pm yesterday and the end date to be 4:am today.

I have reviewed the tag history binding video but I do not know how to write the expression for the parameters.

I typically use the midnight expression function when setting a specific time. For the end time,

// This will take current date, set the time to midnight, and add 4 hours
// 4am today.  The parameter in the now() function determines poll rate, 0 = poll off
addHours(midnight(now(0)), 4)

For start time, you could take the end date parameter, defined before the start date parameter, and just add -12 hours.

addHours({End Date}, -12)
// or
addHours(midnight(now(0)), -8)
2 Likes

I would make one tweak to Daniel's suggestion, in order to make sure you get a 4am end date even across daylight savings time changes:

addHours(addDays(midnight(now(0)), 1), -20)
1 Like

Wow, I never thought of daylight savings when using that :eyes:

https://docs.inductiveautomation.com/display/DOC81/setTime

setTime(now(0), 4, 0, 0)?

Honestly not sure how this would handle DST (or not).

1 Like

Thank you all for the help.

I was able to test the two different methods.

For the test I simplified the search to today from 3:00 am to 4:00 am.

I could not get the addHours to work.

addHours(addDays(midnight(now(0)), 1), 3)

addHours(addDays(midnight(now(0)), 1), 4)

I did get the setTime to work.

setTime(now(0), 3, 50, 0)

setTime(now(0), 3, 55, 0)

How would I get the setTime to yesterdays date at 4:00 pm?

The addHours works for me? As far as setTime goes..

setTime(addDays(now(0),-1), 3, 50, 0)

I think i see my mistake.

I did not have a -1 for the previous date on the addHours solution.

Does the one you show below set the time the previous dat at 3:50 am? If that is the case if I needed the time to be 16:00 the day previous would it be 16,0,0?

setTime(addDays(now(0),-1), 3, 50, 0)

Yep, it uses 24hr, so 16 would be 4 pm on setTime.
here is a link to the Ignition manual appendix on expression functions, which have explainations and examples for all expression functions. This is an invaluable resource :slight_smile: Expression Functions - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)

1 Like