doujiayao8433 2018-02-26 21:34
浏览 184
已采纳

将DB2中的整数转换为日期间隔,以便mysql插入

I have a php script with this select query:

$plcQueryDB2 = " 

    select  
            cstnoc AS DEALER,
            framec AS FRAME,
            covr1c AS COVER,
            colr1c AS COLOR ,
            extd1d AS SHIPDATE
      FROM GPORPCFL
      group by invnoc,cstnoc, slsnoc, orqtyc, framec, covr1c,colr1c, extd1d
      limit 200
";

The result set is correct, but the issue is I'm using the result to insert into mysql and need the SHIPDATE column in true date format since it's an integer in DB2. It looks like 20180202 whereas I need 2018-02-02 for mysql.

The other factor is I need to use that one value (SHIPDATE) for 2 values on the insert.

I need to insert SHIPDATE + 7 DAYS for start_date and SHIPDATE + 127 DAYS for expire_date.

Here's the insert:

$stmt = $PDO->prepare("
        INSERT INTO placements (sku_id, group_id, dealer_id, start_date, expire_date)
        SELECT id, sku_group_id, :DEALER, :SHIPDATE + 7 day interval, :SHIPDATE + 127 day interval
        FROM skus s
        WHERE  s.frame=:FRAME AND s.cover1=:COVER AND s.color1=:COLOR
    ");

Obviously I get a mysql syntax error at : :SHIPDATE + 7 day interval, :SHIPDATE + 127 day interval

And that's still not putting it into true date format. So I have two issues revolving around the same field here.

What's the best way I can convert to true date format and add the intervals for this select or insert?

I can either ammend the select to convert and add the interval or do it at the insert level, I just don't really know how or which is best.

  • 写回答

1条回答 默认 最新

  • dongwo5589 2018-02-26 21:40
    关注

    If your DB2 date is "$date_from_db2":

    $newdate = date("Y-m-d", strtotime('$date_from_db2'));
    

    That requires an intermediate step, of course.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗