www.webdeveloper.com
Results 1 to 4 of 4

Thread: Adding time

  1. #1
    Join Date
    Jul 2007
    Posts
    37

    Adding time

    I am passing a variable ($emailt) that is a number of hours to a PHP page that then sends an email. I want to add the current time to the number of hours variable and send it in the email. The variable is usually either 12 or 24 .
    If the current time is 7:05 pm I want to add 12 so that the variable would read 7:05am. What I have so far is giving me 7:00 am and no exact minutes.
    How do I add the two times together correctly?


    Code:
      $time = date("g:i a");
    	 $emailt = ($emailt*3600+$time);
    	 echo date("g: i a",$emailt) ;

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,392
    ***never mind, misread the original post...let me think a minute***
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,392
    OK, I think you just want to use the current value of time() as a UNIX timestamp integer, then only use date() when you output it in human-readable format:
    PHP Code:
    $emailt = ($emailt 3600 time());
    echo 
    date("g: i a"$emailt) ; 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Jul 2007
    Posts
    37
    Thanks NogDog, that worked!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles