PHP strtotime returns a 1970 date when date column is null
NULL is interpreted as 0 by strtotime, since it want to be passed an integer timestamp. A timestamp of 0 means 1-1-1970.
So you'll have to check for yourself if $row->depositdate === NULL
, and if so, don't call strtotime at all.
Avoid displaying 1970-01-01 when strtotime is false
Try this:
<?php
if(isset($row['date']) && $row['date'] !="")
{
$date = date("d.m.Y", strtotime($row['date']));
}
else {
$date = "";
}
echo $date ; ?>
Laravel set date as 1970 when the value is null
According to this answer In Laravel 5.5+
$request->exists
: Alias for $request->has$request->has
: Determine if the request contains a given input item
key.$request->filled
: Determine if the request contains a non-empty value
for an input item.
All you need - change has
to filled
:
'end_date' => $request->filled('end_date') ? date('Y-m-d H:i:s', strtotime($request->input('end_date'))) : NULL,
Related Topics
How to Prevent Self Closing Tag in PHP Simplexml
How to Upload Image PHP and Insert Path in MySQL
Read the Longest String from an Array in PHP 5.3
Call Parent Constructor Before Child Constructor in PHP
Call to Undefined Function Odbc_Connect() PHP 7
How to Connect to the Database in Openshift Application
Laravel Form Methods VS Traditional Coding
Change Cart Item Prices Based on Custom Cart Item Data in Woocommerce
How to Count the Consecutive Duplicate Values in an Array
Warning Problem: Expects Parameter 1 to Be MySQLi_Result
Error Executing "Putobject" on Aws, Upload Fails
PHP Variable Variables with Array Key
Google Drive API - PHP Client Library - Setting Uploadtype to Resumable Upload
Pass Value from HTML Form to PHP Without Submitting the Form
Insert Value List Does Not Match Column List: 1136 Column Count Doesn't Match Value Count