dongshijiao6890 2010-09-11 13:35 采纳率: 0%
浏览 43
已采纳

无法从db -php获取特定日期

I'm trying to a date timestampted in my mysql db, but my code shows the current date instead.

This is the code that I'm trying:

$db_date = $row_news['nm_date'];
$year = substr($db_date, 0, 4);
$mon = substr($db_date, 4, 2);
$day = substr($db_date, 6, 2);
$orgdate = date("l dS F Y",mktime($mon, $day, $year));
$date = $orgdate

The script is meant to email $date, which should be the value of $row_news['nm_date'], but instead I get the current date "Saturday 11th September 2010.

Thanks for your help.

  • 写回答

2条回答 默认 最新

  • dqp10099 2010-09-11 13:46
    关注

    You're getting today's date because mktime() is not returning a valid value. If you check the manual entry for mktime() - http://www.php.net/mktime - you'll see that the parameter order is:

    mktime ($hour, $minute, $second, $month, $day, $year)
    

    so you probably want:

    $orgdate = date("l dS F Y", mktime(12, 0, 0, $mon, $day, $year));
    

    your code assumes that the date is in YYYYMMDD format (or YYYYMMDDHHIISS). Assuming that is correct, and it's not actually in date format (YYYY-MM-DD) then the above should fix your problem.

    Edit: If the dates are in YYYY-MM-DD format you need to adjust your substrings to allow for the dashes:

    $year = substr($db_date, 0, 4);
    $mon = substr($db_date, 5, 2);
    $day = substr($db_date, 8, 2);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)