Announcement

Collapse
No announcement yet.

TIME output

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TIME output

    Not sure if this is a mysql question or not.

    I have a DB table with a TIME field like 12:30:00, I would like the output on the web page to have one hour subtracted from it. So it would read 11:30:00.

    Can that be done?

    Thanks
    Chad


  • #2
    Assuming the date queried is stored in a variable, you can go about it as follows:

    $newdate = explode(":", $olddate);
    $newdate[0] = $newdate[0] - 1;
    $olddate = "$newdate[0]:$newdate[1]:$newdate[2]";

    Comment


    • #3
      Thank You! It did exactly what I needed it to do!

      Comment


      • #4
        Another way to do it

        That is pretty bad if you get a date like 0:00:00 because you will get a -1, and it is really annoying to check that by yourself.

        You can do it from the select statement right away like

        $data = mysql_query("SELECT date_sub(field, INTERVAL 1 hour) FROM table");

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...
        X