![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6ead9lbRB47OgQPxwPVjQ96ta2BhCN6xq7YnolArXWs_dUyF5onymtaB4f5pHjGAOiZ3lXEo7MdOBmmeoDCfUotHiFyfPhFoSvto0RyTVr3LhKTqX1ySux714d4Sy6UJ0bER502SM9mObQveZkIFy8g46P6JXSRL11TNjMYmlRuBRk-3XI3DMdQNE4TA/s200/sql.png)
I have written before about how to calculate the difference between two dates using SQL. The returned result is given in years, months, and days. But there are some occasions I need the result in days. For example I need a list of customers who have not paid in over 90 days.
Let me jump into my first example. Here I used a DDS file to contain a "date" field, like many ERP databases the date is held in a numeric field:
01 A R TESTFILER 02 A CUSTNBR 10A 03 A ENTERDTE 8P 0 |
To calculate how many days difference there is from the date I wrote this post, I first need to convert the field ENTERDTE from a packed numeric to a "true" date, and then I can perform the calculation using it. I am showing a very simple method of doing this. You might find this will not work in your situation. If any of the numeric fields in the file contain a numeric value that is not a valid date, zero for example, then this example would fail with an error.