Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Formatting time?

    I have this code which formats the date from 2007 07 30 to 30th july, 2007

    $timestamp=strtotime($row['today_inSQL'].' '.$row['time_inSQL']);
    $formated_date=date("dS F, Y", $timestamp);

    Does anyone have any idea how to format the time from say 19:42:04 to 7:42pm

    Thanks
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    <?php
    $str 
    =$row['today_inSQL'].' '.$row['time_inSQL'];
    if ((
    $timestamp strtotime($str)) === false) {
        echo 
    "The string ($str) is bogus";
    } else {
        echo 
    "$str == " date('dS F, Y / h:i:s'$timestamp);
    }
    ?>
    ?>
    is this what your looking for or are you looking for a mysql stored time to be converted to that format?
    ahh sorry i didnt catch the $row[time_inSQL]
    hows that?
    Last edited by rafiki; 07-30-2007 at 03:30 PM.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,058
    Thanks
    10
    Thanked 96 Times in 94 Posts
    Its more efficient to do this in mysql if its applicable to your situation..
    Code:
    "SELECT *,DATE_FORMAT(time_inSQL,'%l%i%p') as time_pretty"
    see this for all format options.. http://dev.mysql.com/doc/refman/5.0/...functions.html
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey thanks, what ive done is put a seperate $, which also works. Thanks for the help.
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •