I need to add 12 hours to a time stored in a text variable in the format H:MM (i.e. its 1:30 not 01:30).

if($_POST['ampm']=='pm')
			{ $mysql_visit_time=$_POST['time'] + 12; }  //ADD 12 hours if it is a PM time HOW HOW HOW this obviously wont work...
else 
			{ $mysql_visit_time=$_POST['time']; }

And Ideas? The $_POST['time'] var can not be changed......

    sounds like you are trying to change from 12-hour format to 24-hour format. if so you don't need to add 12 hours. just use the date() function:

    $_POST['time'] = '1:30';
    $_POST['ampm'] = 'pm';
    
    $mysql_visit_time = date('G:i', strtotime($_POST['time'] . $_POST['ampm']));
    echo $mysql_visit_time; // outputs 13:30
    

      Sounds like your looking for something like the [man]strtotime/man function. 😃 Maybe something like..

      // ... your code
      $time = strtotime($_POST['time']); // To get the UNIX timestamp from the input field.
      $time = strtotime('+12 hours', $time); // To add 12 hours
      // your code ...
      
        Write a Reply...