Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    424

    [PHP] Converting a time

    Hi,

    I have various times stored in my MySQL database in the format HH : MM : SS.

    To allow for my users' timezones I basically wish to take 2 hours off the time.

    For example, 16:18:02 would become 14:18:02.


    I've searched endlessely and can only find how to do this with dates. Is there anybody who can help me out?!


    Many thanks in advance!
    Jon

  2. #2
    Join Date
    Mar 2004
    Posts
    1,301
    PHP Code:
    $t strtotime('-2 hour'strtotime('16:18:02'));
    echo 
    date('G:i:s'$t); 
    this first converts to unix time stamp; from there you can change to time.
    Last edited by orbitz; 09-14-2006 at 01:12 PM.

  3. #3
    PHP Code:
    <?php 
    $test 
    '16:18:02';
    $timestamp strtotime($test);
    $h=date("H",$timestamp)-2;
    $timestamp date('i:s'$timestamp);
    echo 
    ''.$h.':'.$timestamp.'';
    ?>
    just play with it until it works fine Oh well orbitz beat me to it.
    Cheap web hosting
    Any CMS pre-installed
    Joomla Hosting

  4. #4
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3,100
    If you use mysql >= 4.1 you should have subtime() and addtime()
    select subtime( '11:53:14' , '2:0:0') ; should return 9:53:14
    So you can do: select subtime( my_time_field , '2:0:0') AS some_time ....

Posting Permissions

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