duanchi1230 2011-03-24 12:05
浏览 49
已采纳

将SQL日期时间转换为单独的变量

I've been working on a blog commenting system and have been inserting the datetime with NOW(), and I can't quite manage to pull it back into manageable variables,

I've tried using strtotime like following

$date_time1 = strtotime( $row['chron']);
echo $date_time1;

also with mktime

$timeywimey = mktime ( $row['chron'] );

both of these are turning 2011-03-24 12:01:59 into 1300964519

Iif possible I would be looking to split these down into yy,mm,dd hh,mm

  • 写回答

1条回答 默认 最新

  • dtgvl48608 2011-03-24 12:11
    关注

    Although it's just basic string manipulations should be known to every PHP user, you shouldn't split this value but rather format it in desired format, by using either SQL date_format() function or PHP date() one. For the latter it would be

    $date = date("format",strtotime($row['chron']));
    

    for sake of splitting practice, you have either to use some regular expression(harder) or couple calls of explode(), to split value into date ant time parts and then consequently split these into smaller parts.

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

报告相同问题?

悬赏问题

  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义