Find date and time pattern with preg_match

This is how you can find date and time pattern using preg_match

 

<?php
$str
= "'Mplan LXTKLD01.Full Backup' was run on 10/4/2014 at 11:00:00 PM";

preg_match('/([0-9]+)\/([0-9]+)\/([0-9]+)/', $str, $out);
echo
"<pre>";
print_r($out);
preg_match('/([0-9]+)\:([0-9]+)\:([0-9]+)/', $str, $out);
print_r($out);
echo
"</pre>";
?>


Array
(
    [0] => 10/4/2014
    [1] => 10
    [2] => 4
    [3] => 2014
)
Array
(
    [0] => 11:00:00
    [1] => 11
    [2] => 00
    [3] => 00
)