dongzhuo7291 2012-10-26 15:03 采纳率: 100%
浏览 15
已采纳

如何在PHP中转换(非常)旧日期?

I have to migrate an Access database to MySQL. I have two problems: first is year is specified with two digits; second is that this is a birthday database. For example I have strings like this:

"06/12/76 00:00:00"
"10/15/02 00:00:00"

Which year is refering last one (October 15th)? I'll assume that all dates which have a year value over 12 are refering to 19XX and the other (from 0 to 12) to this century: 20XX.

Once resolved this problem I need to format these dates. I've try this:

$bd = strtotime($birth);
if ($bd > time()) {
    $bd = strtotime("-100 years", $bd);
}
$birth = sua_date_unix2mysql($bd);

But the problem is strtotime only is able to manage dates after 1970. Any idea to resolve this problem?

NOTE: Datetime is not available (version 5.2)

  • 写回答

2条回答 默认 最新

  • duanhongyi2964 2012-10-26 15:10
    关注

    Just manipulate those dates as strings.

    // "06/12/76 00:00:00"
    list($month, $day, $year) = explode('/', $birth);
    // $year is actually "76 00:00:00"...
    $year = (int)$year;
    
    $century = 2000;
    if (($century + $year) > date('Y'))
        $century = 1900;
    $year += $century;
    $mysql = "$year-$month-$day"; // 19760612 will be recognized by MySQL
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败