# How can I convert dates into numerical values so I can use them in calculations?

**URL:** <https://pug.phocassoftware.com/t/how-can-i-convert-dates-into-numerical-values-so-i-can-use-them-in-calculations/2002>\
**Category:** Ask the Community\
**Created:** [October 12, 2021, 11:14pm UTC](https://pug.phocassoftware.com/t/how-can-i-convert-dates-into-numerical-values-so-i-can-use-them-in-calculations/2002 "2021-10-12T23:14:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexlovenberg](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@alexlovenberg](https://pug.phocassoftware.com/u/alexlovenberg)\
**Post date:** [October 12, 2021, 11:14pm UTC](https://pug.phocassoftware.com/t/how-can-i-convert-dates-into-numerical-values-so-i-can-use-them-in-calculations/2002/1 "2021-10-12T23:14:39Z")

</div>

I am trying to transform a column (using an Expression) to reflect order lead times. I have data for Order\_Date and Recv\_Date, and I would like to be able to subtract them so I easily know how many days the order took to be received.

When I tried I received the following error: “The expression ([Order\_Date]-[Recv\_Date]) is not a valid transfortmation. Exception: The data types nvarchar and nvarchar are incompatible in the subtract operator.”

I also have other metrics I would like to capture that use data currently in date form data. Anyone know how I can easily convert the dates to be used in calculations?

Thanks!

---

<div class="post-metadata">

**Author:** ![brainer](https://sea1.discourse-cdn.com/flex015/user_avatar/pug.phocassoftware.com/brainer/32/1120_2.png) [@brainer](https://pug.phocassoftware.com/u/brainer)\
**Post date:** [October 14, 2021, 7:21pm UTC](https://pug.phocassoftware.com/t/how-can-i-convert-dates-into-numerical-values-so-i-can-use-them-in-calculations/2002/2 "2021-10-14T19:21:39Z")

</div>

I would use the DATEDIFF command ([SQL Server DATEDIFF() Function](https://www.w3schools.com/sql/func_sqlserver_datediff.asp)) . This would also require converting the date fields into a date data type using CAST. Try this:

**DATEDIFF(day, CAST([Order\_Date] as date), CAST([Recv\_Date] as date))**

1. Cast both fields into a date format.
2. Find the date difference (in days) between the two.
