Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
Laravel set date as 1970 when the value is null

Sometimes laravel set date 1970 when the value is null, it's possibile save value as NULL instead 01-01-1970?

 'start_date' => date('Y-m-d', strtotime($request->input('start_date'))),
 'end_date' => $request->has('end_date') ? date('Y-m-d', strtotime($request->input('end_date'))) : NULL,

This code is not working.

How i can solve it?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

In MySQL if the date format is not complete or invalid it is set to the default.

Update your date function to include time, if you have a datetime field you must also pass a time.

date("Y-m-d H:i:s");

 
'start_date' => date('Y-m-d H:i:s', strtotime($request->input('start_date'))),
'end_date' => $request->has('end_date') ? date('Y-m-d H:i:s', strtotime($request->input('end_date'))) : NULL,

over 4 years ago · Santiago Trujillo Report

0

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,
over 4 years ago · Santiago Trujillo Report

0

Please try the below code

Need to check whether request has available then convert to time

'start_date' =>$request->has('start_date') ? date('Y-m-d', strtotime($request->input('start_date'))) : NULL,

'end_date' => $request->has('end_date') ? date('Y-m-d', strtotime($request->input('end_date'))) : NULL,

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!