2017-09-08 21:00 阅读 159


I have a db table that contains time in the following format hhmm.

I need to split hour from minutes. I think I can use something like

substr($time, 0, 2);

It works well when my time looks like: 1430, however I'm not sure what to do when I have something like 710.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongzhuo1880 dongzhuo1880 2017-09-08 21:04

    You can use a negative offset instead, that counts backwards from the end of the string

    substr($time, 0, -2); 
    点赞 评论 复制链接分享