Calculate days remaining from today's date


I am trying to build a Kreport that provides a figure for ‘days remaining’ when today’s date is compared to a target date in the future. Can anyone tell me what the custom code would look like to do this?

Also, I don’t know if this is possible but I would like the days remaining figure to change colour when it reaches a certain threshold. Is this possible?

Any help gratefully received.

Many thanks

use CustomFunction manipulate tab
In example below I display remaining days before opportunity closing date.
I dragged field closed_date twice. The second time I apply a custom SQL calculating the number of days remaining.

For color please check thread Can we set color in field on the KReport?