Reputation:
Okay so I would like to pass date and time to my script using GET. Right now it checks the exact value with the database, but it contains spaces.I want to convert 1 line e.g.
2015-03-04-03:03:34
I want to verify this string matches the timestamp in my sql table which displays like:
2015-05-03 12:03:23
Thanks
Upvotes: 1
Views: 54
Reputation: 1855
just use strtotime($variable)
http://php.net/manual/en/function.strtotime.php
but be aware that you may need to modify your joining characters. Forward slash (/) signifies American M/D/Y formatting, a dash (-) signifies European D-M-Y and a period (.) signifies ISO Y.M.D. thus double check your results before you apply this solution.
Upvotes: 0
Reputation: 27092
You can use regex with patter remove all between date and time:
$str = '2015-03-04-03:03:34';
$str = preg_replace('~(\d{4}-\d{2}-\d{2})(.+)(\d{2}:\d{2}:\d{2})~', '$1 $3', $str);
echo $str; // 2015-03-04 03:03:34
Upvotes: 0