laravel - 如何添加一天并同时指定该日期的静态时间?
问题描述
好我有一个问题,希望你能帮助我,事实是我必须从我的数据库中获取一些时间戳并添加它们一天,好吧,好吧,我使用 carbon addday(),但是由于 carbon 确实不想比较我的时间戳然后我必须转换为字符串,通过解析我可以将它们同化为碳,但在那个过程中我的日期发生了变化,日期是正常的,但由于某种原因,时间加起来是几个小时和这完全改变了我正在寻找的结果,我该如何解决?我通过我的命令:
<?php
namespace App\Console\Commands;
use App\p;
use App\Pe;
use App\Mail\SendMailable;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Carbon\Carbon;
class LimpiarDiario extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'Task:LD';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Tasks';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$datedi = p::select('p.Date', 'p.coddate')
->where('p.cod_paperiod', '=', 1)
->get();
foreach ($datedi as $dateda)
{
$cod = $dateda->coddate;
$now = Carbon::now();
$dateli = $dateda->Date;
$dateinter = strtotime($dateli);
$datecar = Carbon::Parse($dateinter);
$datetrans = $datecar->addDay();
$datenue= $datetrans->toDateTimeString();
if ($dateda->Date < $now)
{
$prueba= p::where('coddate','=', $cod)
->update(['Date' => $datenue]);
}
}
}
为了显示问题,我的 dateda 的结果是:{"Date":"2020-06-12 16:00:00.000000","coddate":53}
然后它变成 dateli 并且它的值是:2020-06-12 16:00:00.000000
它再次变成 dateinter 并且它的值是:1591992000
最后它变成带有变量 datecar 的碳:"2020-06-13T20:00:00.000000Z"
并且由于某种原因你现在可以看到它将原始时间增加 4 小时,因此当我注册结果时,它会为我保存日期:2020-06-13 20:00:00
当期望的结果应该是:2020-06-12 16:00:00
因此,正如所解释的,我必须寻求帮助才能知道如何设置解析时间,或者如何在不更改时间的情况下将其转换为时间戳。
解决方案
为什么所有这些脚本只是为了做出更新声明......
$now=Carbon::now();
p::where('p.cod_paperiod', '=', 1)->where('date','<',$now)
->update(['Date' => DB::raw("Date + INTERVAL 1 DAY")]);
推荐阅读
- rest - 选择哪个http客户端
- flutter - Flutter 'samples.json' 不下载示例示例 ID
- android - 自动可调textview改变高度android
- c# - 无法在编排项目名称中使用点 (.)
- javascript - 在线性时间内查找长度为 N、数字 1 到 N-1 的数组中的重复项,而无需使用额外的 obj/arr 来跟踪计数
- linux - 如何在 Linux 中使用 md5sum 创建递归文件列表并输出到 csv
- excel - VBA - 从创建的报告中移动数据的简单宏导致崩溃或“找不到项目或库”
- spring - 如何在 Spring Integrtion 中测试 MessageChannel?
- ruby-on-rails - React On Rails 调试
- java - 使用类在java中猜测数字的程序