How can I convert a string, such as 02:00 to a timestamp that can be saved into the databse as an integer? It can either be mm:ss or hh:mm depending on what I want the user to input in the form. But it's always either mm:ss or hh:mm
strtotime
delivers unreliable results, so I figured it's not the right way to go. Is there another way I'm not aware of?
EDIT
To ask the question in a better way: I have a form that has an input for mm:ss and an input for hh:mm values. I need to convert these values to unix timestamps. Obviously strtotime is not the way to go for this.
You cant convert only minutes or hours to timestamp, you need to have a date. In php you can use mktime function:
$time = mktime($hours, $minutes, $seconds, $month, $day, $year);
Docs: http://php.net/manual/en/function.mktime.php
For example you have hh:mm input
$input = '02:15';
$arr = array_map('intval', explode(':', $input));
// Create timestamp with selected time for today date
$time = mktime($arr[0], $arr[1], 1, date('m'), date('d'), date('Y'));