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 2 of 2
  1. #1
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts

    timestamp + string

    Hi

    I have a start time for a schedule and in my DB i have a duration which is a string. What I want to do is calculate the end time

    end_time= start_time + (duration)

    Start time is stored in the DB as a SQL Time data type. I convert it to a timestamp

    PHP Code:
     $timestamp=strtotime($row['time']); 
     
    $strt_time=date("g:i"$timestamp); 
    So how is the best way to get end time when one is a string in hours and the other a timestamp
    You can not say you know how to do something, until you can teach it to someone else.

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    PHP Code:
    $timestamp=strtotime($row['time']); 
    $strt_time=date("g:i"$timestamp); 
    $coef=(int)($row['duration']);
    $end_time=date("g:i",  $timestamp+($coef*3600)); 
    This seems to work but can i rely on this?
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

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