Time format in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tamimmakki
    New Member
    • Nov 2007
    • 6

    #1

    Time format in php

    hi guys,
    I want to display time format 22:00 instead of 00:22:00 as stored in mysql. I am using mysql and php. data type in php is time not timestamp. thnx in advance for help
  • realin
    Contributor
    • Feb 2007
    • 254

    #2
    Originally posted by tamimmakki
    hi guys,
    I want to display time format 22:00 instead of 00:22:00 as stored in mysql. I am using mysql and php. data type in php is time not timestamp. thnx in advance for help

    hello tamimmakki,

    well its very simple to do that.. fetch the datetime from mysql, change it to string and then use date function to display the way you want.. Though, i would advice you to store date & time into VARCHAR format in mysql, so u can skip the first step.. well a working example goes in here..

    [PHP]
    <?php

    //make connection & stuff and fetch data
    $fetch=date('g: m:i');
    $str=strtotime( $fetch);
    echo date('H:M',$str );
    ?>
    [/PHP]

    cheers !!

    Comment

    Working...