Sugar icon indicating copy to clipboard operation
Sugar copied to clipboard

Subtract units from date

Open javisperez opened this issue 8 years ago • 3 comments

Hello!

Is there a way to subtract units (in my case days) from a date? something like:

const to = Sugar.Date.create('today');
const from = to.subDays(3);

I can't find how to do something like that, thank you!

javisperez avatar Feb 13 '17 20:02 javisperez

Yes! You can use daysSince.

andrewplummer avatar Feb 16 '17 01:02 andrewplummer

Ah apologies, I see you were trying to add the unit itself. Well, the answer to your question is add with a negation, so to.addDays(-3). However, the more I think about this it's gone unexamined that the stance is simply to negate the operator when, for example, both advance and rewind exist for parity. Let me consider adding this for the next version.

andrewplummer avatar Feb 16 '17 01:02 andrewplummer

Thank you, i didnt know you could use negative values with addDays, that will work for me, thanks! and yeah, also, that could be a cool feature :), thanks again!

javisperez avatar Feb 16 '17 13:02 javisperez