How to save time in database in timeformat in Laravel 5? -


i have been trying while saving time in database in timeformat 10:00:00.

what want pick time timepicker , save data(time) in timeformat.

here have done:

  • i have used timepicker gets data in format 10:52 am.

  • i have used accessor methods save time follows:

    public function setrtimeattribute($value) {     $this->attributes['r_time'] = date('h:i:a', strtotime($value)); } 
  • my post controller in case needed follows:

    public function postsessionreservation(request $request,$profile_slug) {     $restaurant = restaurant::where('slug_profile', $profile_slug)->select('name','ar_name','slug_profile','id')->firstorfail();      $this->validate($request,[         'no_of_seats'=>'required',         'r_date'=>'required',         'r_time'=>'required',         'restaurant_id'=>'required',     ]);     $data = [         'no_of_seats'=>$request->no_of_seats,         'r_date'=>$request->r_date,         'r_time'=>$request->r_time,         'restaurant_id'=>$request->restaurant_id     ];     $minutes = 1;      session::put('reservation',json_encode($data),$minutes);      return redirect($restaurant->slug_profile.'/complete-reservation'); } 

but saves time 12:00:00 each time.

i not know how 12:00:00 generated whenever save time. tried lot not figure out.

hope guys me solve this.

thanks in advance.

first remove spaces between time "10 : 52 am" "10:52 am" , change line this

$this->attributes['r_time'] = date("h:i", strtotime( $value )); 

this surely test it.

for example can remove spaces through

$a = '10 : 52 pm'; $x = preg_replace('/\s*:\s*/', ':', $a); date("h:i", strtotime($x)); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -