1

I am getting following dates from the bootstrap date picker in my laravel backend.

[start_date] => Array
    (
        [year] => 2018
        [month] => 2
        [day] => 1
    )

[end_date] => Array
    (
        [year] => 2018
        [month] => 4
        [day] => 30
    )

I want to convert the date in to php date i.e

start_date = "2018-02-01";
end_date = "2018-04-30"

If anyone is providing answers please provide the specific code or links.

Sagar Ahuja
  • 726
  • 6
  • 23

4 Answers4

1

You can use implode to avoid long code:

$get_start_date = implode('-',$RequestData['start_date'])  
$get_end_date = implode('-',$RequestData['end_date'])  

$start_date = date("Y-m-d", strtotime($get_start_date));
$end_date = date("Y-m-d", strtotime($get_end_date));
HamzaNig
  • 1,019
  • 1
  • 10
  • 33
0

You can use date_create PHP Function :

$start_date=date_create($date['start_date']->year.'-'.$date['start_date']->month.$date['start_date']->day);
$start_date=$start_date->format('Y-m-d')

$end_date=date_create($date['end_date']->year.'-'.$date['end_date']->month.$date['end_date']->day);
$end_date=$end_date->format('Y-m-d')
HamzaNig
  • 1,019
  • 1
  • 10
  • 33
0

You can use Carbon

$s_date = \Carbon\Carbon::create($start_date[0], $start_date[1], 
$start_date[2],0,0,0);
David Auvray
  • 288
  • 1
  • 3
  • 20
0

Carbon is best to use https://carbon.nesbot.com/docs/

$dt = Carbon::create($year, $month, $day);
echo $dt->toDateString();
Faiez
  • 285
  • 1
  • 6
  • 20