Parse Bootstrap Date Range Picker value in Laravel Controller?

时间:2017-12-18 06:04:06

标签: php twitter-bootstrap laravel

I have a bootstrap date range picker input which gives a value similar to something like this:

  "dateRange" => "19 Nov 2017 - 18 Dec 2017"

I need to parse this value in my Controller and get two dates out of it. Start date and end date. (Preferably using Carbon)

How can I go about doing this?

3 个答案:

答案 0 :(得分:1)

You can simply use explode() for this(DEMO):

$dates = explode(' - ', '19 Nov 2017 - 18 Dec 2017');
var_dump($dates);

答案 1 :(得分:1)

Extending answer by @mega6382, you could parse the dates after exploding them

$dates = explode(' - ', '19 Nov 2017 - 18 Dec 2017');
$start_date = Carbon::parse($dates[0]);
$end_date = Carbon::parse($dates[1]);

答案 2 :(得分:1)

<?php

$date  = explode('-',"19 Nov 2017 - 18 Dec 2017");// dateRange is you string
$dateFrom = $date[0];
$dateTo = $date[1];
$DateNew= strtotime( $dateFrom );
echo $dateFrom = date( 'Y-m-d', $DateNew);
$DateNew= strtotime( $dateTo );
echo $dateTo = date( 'Y-m-d', $DateNew);