change date format in php

php

Solution

You are using deprecated functions. Use the preg_match instead. Also the call to preg_match should be in a if test.

<?php
$datedue = '22/01/2010';
if(preg_match('@([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})@', $datedue, $redgs)) {
    $billdate=$redgs[3]."-".$redgs[2]."-".$redgs[1];    
    echo $billdate; // prints  2010-01-22 
}
?>

Problem

i develop a webpage , in that i need to change the date format from 22/01/2010 to 2010-01-22 i use the following function but i am getting a warning as "Deprecated : Function ereg() is depreceted in c:\wamp\www\testpage.php on line 33" . Is there anyway to hide that error or is there any other way to change the date format ? Please help me to solve this issue . Thanks in advance . ``` $datedue = $_REQUEST['txtJoiningdate']; $r = ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $datedue, $redgs); $billdate=$redgs[3]."-".$redgs[2]."-".$redgs[1]; ```

Original source