# Pls explain DateTime.SubtractInterval

Could someone explain this?

``````Var ldDateFrom As DateTime
Var ldDateTo As DateTime
Var ldToFilterDate As DateTime
Var ldTargetDate As DateTime

ldToFilterDate = DateTime.FromString(txtTarget.Value)  //contains a SqlDate 2020-05-05

// First of this month at midnight
ldDateFrom = ldToFilterDate.SubtractInterval(0, 0, ldToFilterDate.Day - 1, _
ldToFilterDate.Hour, ldToFilterDate.Minute, ldToFilterDate.Second)
``````

// This seems it would set it to 2020-05-04 I don’t understand this.

``txtFirstOf.Text = ldDateFrom.SQLDate  // Show 2020-05-01 Why``

Haven’t you subtracted 0 years, 0 months, 4 days, and the time to take it back to midnight?

Rather than `ldToFilterDate.Day - 1`, that should be 1.

This code sets to to 2020-05-01,

I don’t understand why?

Surely 2020-05-05 minus 4 days and some amount of time is 2020-05-01. (Whatever the time values got set to in `ldToFilterDate`, you subtracted them exactly.)

But the code is not doing that, it’s subtracting 1 day, at least that’s how I see it???

But you keep telling me its 4 days. At least, to me the difference between 2020-05-05 and 2020-05-01 is 4 days.

ldToFilterDate.Day is using the ‘day’ part of the original SQLDate value, for this example 5
SubtractInterval has a calculation on the day section that say: `ldToFilterDate.Day - 1`
So every time you use that calculation it will subtract the number of days -1. If ldToFilterDate.Day is 20, it will subtract 19, if it is 5 it will subtract 4 and so on.

Thank you, now I get it!