How to Subtract Days in MySQL
SELECT DATE(NOW()-INTERVAL 15 DAY) For a list of units see http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
SELECT DATE(NOW()-INTERVAL 15 DAY) For a list of units see http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
php supports c style date functions. You can add or substract date-periods with English-language style phrases via the strtotime function. examples… $Today=date(‘y:m:d’); // add 3 days to date $NewDate=Date(‘y:m:d’, strtotime(‘+3 days’)); // subtract 3 days from date $NewDate=Date(‘y:m:d’, strtotime(‘-3 days’)); // PHP returns last sunday’s date $NewDate=Date(‘y:m:d’, strtotime(‘Last Sunday’)); // One week from last sunday … Read more
UPDATED: January 19, 2016 As of moment 2.8.4 – use .add(5, ‘d’) (or .add(5, ‘days’)) instead of .add(‘d’, 5) var new_date = moment(startdate, “DD-MM-YYYY”).add(5, ‘days’); Thanks @Bala for the information. UPDATED: March 21, 2014 This is what you’d have to do to get that format. Here’s an updated fiddle startdate = “20.03.2014”; var new_date = … Read more
If you want logical calendar days, use DAYS.between() method from java.time.temporal.ChronoUnit: LocalDate dateBefore; LocalDate dateAfter; long daysBetween = DAYS.between(dateBefore, dateAfter); If you want literal 24 hour days, (a duration), you can use the Duration class instead: LocalDate today = LocalDate.now() LocalDate yesterday = today.minusDays(1); // Duration oneDay = Duration.between(today, yesterday); // throws an exception Duration.between(today.atStartOfDay(), … Read more