-1

I need a time comparison.

I have a database field with a varchar field that contains column name date.

I have fetched two dates on the bases of id.like in code.

Now i want to convert these strings into actual date/time so I can compare them.

I am trying this:

    $sql="SELECT date From tbl_info where  id=12 "; //first date string
    $sql2="SELECT date From tbl_info where id=14 "; //2nd date string
    $result= mysql_query($sql) or die(msyql_error());
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
      {
     $date=$row["date"]. "<br>";       
     echo  $date ;
      }
     $result2= mysql_query($sql2) or die(msyql_error());
      while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) 
       {
       $date2=$row2["date"]. "<br>";
        echo  $date2;
        }
       $value=strtotime('H,i',$date);
      echo "<br/>Value= :".$value ;

      $value2=strtotime('H,i',$date2);
      echo "<br/>Value2= :".$value2;

RESULTS:

Value= :-48386

Value2= :-48386

What is the actual way to do it right, because strtotime does not work.

chriz
  • 1,580
  • 19
  • 27
Esar-ul-haq Qasmi
  • 1,052
  • 1
  • 14
  • 30
  • 1
    There is **no more support** for `mysql_*` functions, they are [**officially deprecated**](https://wiki.php.net/rfc/mysql_deprecation), **no longer maintained** and will be [**removed**](http://php.net/manual/en/function.mysql-connect.php#warning) in the future. You should update your code with [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) to ensure the functionality of your project in the future. – Kermit Oct 31 '14 at 12:09
  • 1
    Why would you store a date in a varchar when MySQL has much more suited [date and datetime types?](http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html) – Digital Chris Oct 31 '14 at 12:16

1 Answers1

1

try with

date('H,i', strtotime($date)); //$date will be the date you want to use

$value2=date('H,i', strtotime($date2));
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87