Reputation: 3596
For example i'm getting number 25 from user, and how can i generate a complete date with Carbon or any PHP helper?
For example today is 22 April 2015, then it will returns 25 April 2015.
If today is 26 April 2015, then it will returns 25 May 2015.
Upvotes: 0
Views: 2087
Reputation: 152910
This is basically the same approach as @MarkBaker's but it uses Carbon:
$next = 25;
$date = Carbon::today()->day($next);
if($date->isPast()){
$date->month++;
}
echo $date;
Upvotes: 5
Reputation: 212442
$date = 25;
$now = new DateTime();
$then = clone $now;
$then->setDate($now->format('Y'), $now->format('m'), $date);
if ($then < $now) {
$then->add(new DateInterval('P1M'));
}
echo $then->format('Y-m-d');
Upvotes: 1