Lets take any month be of 30 days, then for the date 25/02/2015 when we add 10 days it becomes 5/03/2015 but there are months which are of 29 and 31 days as well.If a month be of 31 then adding 10 days to 25/04/2015 would be 04/05/2015 not 05/05/2015.Does date functionality of MySQL ,PHP and Carbon function of laravel produce correct date after addition or substraction by detecting total days of particular months strictly as per calendar or just assumes every month to be of 30 days?What are the best tools for correct date manipulation?
Asked
Active
Viewed 205 times
-3
-
Where is the code you have tried? – Sougata Bose May 07 '15 at 06:58
-
'Month of 30'? are you drunk? They say that there are no daft questions, but this appears to be the exception that proves the rule. – Strawberry May 07 '15 at 07:04
-
Pretty easy to find out just by trying it, you could have written a script to test this faster than you could have written the question..... no, PHP, MySQL, DateTime, Carbon, etc aren't that stupid... they were written by people who do know that the number of days in a month varies..... they were written by people who even know that not every day is 86400 seconds long – Mark Baker May 07 '15 at 07:09
2 Answers
0
You can use like this to get current date
,previous date
and next date
<?php
$date = date('Y-m-d');
$prev_date = date('Y-m-d', strtotime($date .' -1 day'));
$next_date = date('Y-m-d', strtotime($date .' +1 day'));?>

Vivek Singh
- 2,453
- 1
- 14
- 27
0
PHP, yes.
<?php
$date=date_create("2015-02-25");
date_add($date, date_interval_create_from_date_string("10 days"));
echo date_format($date,"Y-m-d");
// echos 2015-03-07
date_add($date, date_interval_create_from_date_string("-10 days"));
echo date_format($date,"Y-m-d");
// echos 2015-02-25
MySQL, yes.
DATE_ADD(SomeDate, INTERVAL 10 DAY)
DATE_SUB(SomeDate, INTERVAL 10 DAY)

Drakes
- 23,254
- 3
- 51
- 94