按小时和分钟分割时间

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.

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

substr($time, 0, -2);