Using timestamp with mysql : mysql_fetch_array « MySQL Database « PHP






Using timestamp with mysql

 
<html>

<head>
<title>Using timestamp</title>
</head>

<body>
<?php

  $conn = mysql_connect( "localhost", "userName", "password" ); 

  $rs = mysql_select_db( "my_database", $conn );

  $sql = "select * from guestbook where id=1";

  $rs = mysql_query( $sql, $conn );
 
  #split the timestamp into organized date format 
  while ( $row = mysql_fetch_array( $rs ) ) 
  {
    $datetime = $row["time"];
    $year = substr( $datetime, 0, 4 );
    $mon  = substr( $datetime, 4, 2 );
    $day  = substr( $datetime, 6, 2 );
    $hour = substr( $datetime, 8, 2 );
    $min  = substr( $datetime, 10, 2 );
    $sec  = substr( $datetime, 12, 2 );
    $orgdate = date("l F dS, Y h:i A", mktime( $hour, $min, $sec, $mon, $day, $year ) );
    echo( "Time of entry: " . $orgdate );
  }

?>

</body>
</html>
  
  








Related examples in the same category

1.An Example of Using the Old MySQL Extension
2.while loop and mysql_fetch_array() function
3.Get data from database
4.mysql_fetch_array-2.php
5.mysql_fetch_array.php
6.Retrieving and Displaying Results