Newbie 123
Newbie 123

Reputation: 264

Saving date as a string in Laravel

How do I make a date that was initially in the format 18-10-2019 to be 181019? If the user registers, then the user will get a token number in the form of the date registered plus 1.

Upvotes: 0

Views: 74

Answers (2)

Udhayan Nair
Udhayan Nair

Reputation: 552

You can format it as such;

$date = Carbon::now();
$formattedDate = $date->format('dmY');

Upvotes: 0

Vibha Chosla
Vibha Chosla

Reputation: 713

You can achieve it by using date function

$d1 = '18-10-2019';
$d2 = date('dmy', strtotime($d1));
echo $d2; // 181019

Upvotes: 2

Related Questions