Can not convert date time to proper format using PHP

I am facing one issue.I cannot properly format the datetime using PHP. I am explaining my code below.

<?php
$enddate='20/04/2017 12:30 AM';
$result=date('Y-m-d h:i:s',Strtotime($enddate));
echo $result;
?>

Here I am getting the output as 1970-01-01 01:00:00 which is wrong but here I need to get 2017-04-20 12:30:00 as output. Please help me to resolve this issue.


Source: stackoverflow-php

Carbon date saves as 0000-00-00 in Laravel

I am trying to save a date in Laravel, but it keeps defaulting to 0000-00-00.

Migrations setup:

$table->date('audit_date')->nullable();

It needs to be nullable because it’s not initially added, this function edits the row.

Controller:

$date = Carbon::createFromFormat('d/m/Y', $request->get('datepicker'))
            ->toDateString();

If I output the $date, it shows "2017-03-16"

Full snippet showing where the date is added:

$date = Carbon::createFromFormat('d/m/Y', $request->get('datepicker'))
           ->toDateString();

    $audit = Score::where('id', 1)->first();
    $audit->audited = 1;
    $audit->audit_date = $date;
    $audit->save();

Why does it save as 0000-00-00?


Source: stackoverflow-php

Laravel – Get row that has today between begin and end

I have a table that has two dates fields, begin and end.

I’m trying to get all rows that have begun but not yet ended. and if today is less than begin, they shouldn’t be included. and if today is grater than end they shouldn’t be included.

I’m using laravels eloquent. Here is what i’ve tried

$now = CarbonCarbon::now();

$promos = AppModelsLivePromo::
    where("begin", "<=", $now)
    ->where("end", ">=", $now)
    //Other conditions
    ->get(); 

This seemingly work, but it also selects rows that are greater have already ended.
How can i make this work as i expect?


Source: stackoverflow-php