MySpaza - How To
Web Design Tips and PC and Linux Related Information

Subscribe
 



    follow me on Twitter

    PHP Get Time Function - Easily convert mysql datetime to user friendly output.
    PHP get make time function - convert mysql datetime day month year hour minute second

    Added: 2008-05-19 08:49:02

    I always have a bit of a nightmare with Datatime and Timestamps. I have come up with a simple function for converting a datatime into a more user readable version.

    function gettime($gettime,$ops=0) {
      list($date, $time) = split(' ', $gettime);
      //echo "Date: $date, Time: $time<br />"; 
      list($eyear, $emonth, $eday) = split('-', $date);
      //echo "Year: $eyear, Month: $emonth, Day: $eday";
      list($ehour, $emin) = split(':', $time);
      //echo "Hour: $ehour, Min: $emin";
      
      if($ops==0) { 
       return date("j F Y", mktime($ehour, $emin, 0, $emonth, $eday, $eyear));
      } elseif ($ops==1) {
       return date("j F Y, H:i:s", mktime($ehour, $emin, 0, $emonth, $eday, $eyear));
      }    
     }

    The function can contain an argument:

    <? gettime($row['mysql_datetime'],1); //This will display the full Time and Date entered in the Mysql Database; ?>

    <? gettime($row['mysql_datetime'],0); //This will display the Time entered in the Mysql Database; ?>

     




    Add a comment to this post
    Email confirmation is required for each post

    Name:
    Email:
    Comment:
     

    Comments from other users:




    Copyright MySpaza.Co.Uk - 2010