Sugar
Sugar copied to clipboard
Subtract units from date
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!
Yes! You can use daysSince.
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.
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!