> For the complete documentation index, see [llms.txt](https://kb.logicerp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/defining-custom-columns-in-reports-and-grids-with-expressions/datediff-function.md).

# DateDiff () Function

**YouTube:** [How to Use the DateDiff () Function in Report Custom Columns?](https://www.youtube.com/watch?v=SXu7wbNw8VU)

## How to Use the DateDiff () Function in Report Custom Columns?

In this tutorial, we’ll learn how to calculate the **difference between two dates** using the `DateDiff` function in a report grid. This is helpful for calculating aging, due periods, or durations between dates.

***

### Accessing the Expression Designer:

* Navigate to the **Reporting** section.
* Open the **Sales Register Detailed Report** or any **"Report".**
* Go to **Setup Column Attributes**.
* Here, you'll see a list of available columns that can be used to build expressions.
* Click on **"Add/Edit Expression Columns"** where you can write your expression using predefined functions.

<figure><img src="/files/QqZlgPb7nJy0O1lsvxB5" alt=""><figcaption></figcaption></figure>

* Before adding the expression to the report, go to **Other Settings**.
* Ensure the **Script Editor** is set to **VBScript**.

<figure><img src="/files/US8rZzar6siLdptkuOMX" alt=""><figcaption></figcaption></figure>

* Click **Save**.
  * *Note: VBScript is the default for new configurations but always verify this setting.*

### Writing Your First Expression

* Every expression must start with the script header: **'#@LSCRIPT**

<figure><img src="/files/K37bBe9AvTCKOiLXaocU" alt=""><figcaption></figcaption></figure>

* Click the (+) Plus icon to create a new expression.
* Fill in the required fields:&#x20;
  * **Expression Name** – A unique name for your expression.
  * **Expression Type** – Choose either **Text** or **Numeric** depending on the expected output.

<figure><img src="/files/9jljzCmx2wf2EXmzBbT9" alt=""><figcaption></figcaption></figure>

### Creating a Simple DateDiff() Expression

* Double-click the new expression name to insert it into the script editor.
* Define the expression using the syntax:
  * **Expression Name** = DATEDIFF("D",CDATE(BILL\_DATE),NOW)

    * `"D"` → Calculates difference in **days**
    * `CDate(BILL_DATE)` → Converts the bill date string to a date
    * `Now` → Represents the current system date

    **Other interval options:**

    * `"M"` – Months
    * `"Y"` – Years
    * `"D"` – Days (most commonly used)

<figure><img src="/files/UPbbGMgp9TI8IZEA5WsI" alt=""><figcaption></figcaption></figure>

* Save the expression once defined.
* Scroll down and **check the box** beside the expression name to enable it.

<figure><img src="/files/MQzcb1J5JYmGsj12kOF8" alt=""><figcaption></figcaption></figure>

* Save and proceed to check the effect.
* **Refresh the report** to view the final result.

<figure><img src="/files/y1Qh5azXu0kzB7O8GIof" alt=""><figcaption></figcaption></figure>

***

### Output:

* If `BILL_DATE = 01/06/2025` and today is `09/06/2025`,\
  the column will show: `8`

This expression is widely used in reports like **aging analysis**, **credit control**, and **follow-up tracking**.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/defining-custom-columns-in-reports-and-grids-with-expressions/datediff-function.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
