gpt4 book ai didi

mysql - 尝试将 DateTimePicker 中的值插入数据库,但导致日期时间格式无效

转载 作者:行者123 更新时间:2023-11-29 18:22:20 25 4
gpt4 key购买 nike

我正在尝试插入 DateTimePicker 中的值,因为它没有获取这些值,因为我是这个平台的初学者。那么如何转换格式并保存到数据库中。

public function store(Request $request) {

$input = Request::all();
$input['dob'] = Carbon::now();
$input['app_date'] = Carbon::now();
patient_user::create($input);
return redirect('patient_user');
$dob = Date::createFromFormat('Y-m-d');
$app_date = Date::createFromFormat('Y-m-d');
$dob->setTime(0, 0, 0);
$app_date->setTime(0, 0, 0);
echo $dob->getTimestamp();
echo $app_date->getTimestamp();

DB::table("patient_users")->insert([
"patient_firstname"=>$request->get("patient_firstname"),
"patient_lastname"=>$request->get("patient_lastname"),
"middle_name"=>$request->get("middle_name"),
"gender"=>$request->get("gender"),
"dob"=>(new DateTime($request->get('dobe')))->format('Y-m-d'),
"pat_age"=>$request->get("pat_age"),
"app_date"=>(new DateTime($request->get('app_date')))->format('Y-m-d'),
"app_time"=>(new DateTime($request->get('app_time')))->format('H:i:s'),
"branch_location"=>$request->get("branch_location")
]);
}

Migration:
Schema::create('patient_users', function (Blueprint $table)
{
//$table->increments('id');
//$table->increments('patient_id');
$table->string('patient_firstname');
$table->string('patient_lastname');
$table->string('middle_name');
$table->boolean('gender');
$table->date('dob');
$table->increments('pat_age');
$table->date('app_date');
$table->dateTimeTz('app_time');
$table->string('branch_location');
$table->timestamps();
}

最佳答案

问题是你在函数的开头有一些不属于那里的代码。并且return后的代码不会执行。

请将您的函数替换为以下代码并告诉我它是如何工作的:

public function store(Request $request) {
DB::table("patient_users")->insert([
"patient_firstname"=>$request->get("patient_firstname"),
"patient_lastname"=>$request->get("patient_lastname"),
"middle_name"=>$request->get("middle_name"),
"gender"=>$request->get("gender"),
"dob"=>(new DateTime($request->get('dobe')))->format('Y-m-d'),
"pat_age"=>$request->get("pat_age"),
"app_date"=>(new DateTime($request->get('app_date')))->format('Y-m-d'),
"app_time"=>(new DateTime($request->get('app_time')))->format('H:i:s'),
"branch_location"=>$request->get("branch_location")
]);
}

关于mysql - 尝试将 DateTimePicker 中的值插入数据库,但导致日期时间格式无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46467810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com