Domas
Domas

Reputation: 1133

Get an hour and minutes of a timestamp in cakePHP/ PHP

Sounds like a silly queston, but I need a quick answer and could not find it.

I have a timestamp: '15:40:00', and I need to create two separate variables: hours and minutes.

Much much appreciated.

Upvotes: 1

Views: 121

Answers (2)

Glavić
Glavić

Reputation: 43582

You can also use one function sscanf() (variables will be integer type) :

sscanf('15:40:00', '%d:%d:%d', $hours, $minutes, $seconds);

demo

Upvotes: 1

John Conde
John Conde

Reputation: 219934

list() and explode() work well here.

list($hours, $minutes, $seconds) = explode(':', '15:40:00');

Upvotes: 2

Related Questions