I have a db table with a date field startBefore
in ('Y-m-d')
format. There are also 3 other int fields representing years, months and days. What I would like to do is to fill these three fields the new startAfter
date in 'Y-m-d'
format.
For example I have the '2001-11-14' as startBefore
date and I would like to subtract 3 yrs, 7 months, 1 day to get the startAfter
date.
Any ideas how I can accomplish this?
Thanks!
The date_sub() function subtracts some days, months, years, hours, minutes, and seconds from a date.
You can use strtotime() function to get the time difference between two dates (DateTimes) in minutes using PHP.
PHP date() Function The PHP date function is used to format a date or time into a human readable format. It can be used to display the date of article was published. record the last updated a data in a database.
use strtotime('date -years -months -days')
<?php $time = strtotime('2001-11-14 -3 years -7 months -5 days'); echo $date = date("Y-m-d", $time);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With