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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Angry How to get difference time ?

    Hi thanks to all...

    I have 3 variables ;
    1 is $date = (dd-mm-yy)
    2nd is $time = (H:i)

    3rd 1 $today = date('Y-m-d H:i') ;

    my question is how to get difference time (in minutes) between $today - $date $time ?

    I try this, but not get correct answer :
    PHP Code:
    $time_me $time ;  
    $time_me explode(":",$time_me);
    $date_me $date ;
    $date_me explode("-",$date_me); 
    $target =  mktime($time_me[0], $time_me[1], $date_me[1], $date_me[2], $date_me[0]) ;

    $today date('Y-m-d H:i') ;

    $difference =($today-$target) ;

    print 
    $minuts = (int) ($difference/60); 
    please help me

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    where do $time and $date come from?

    if they’re coming from a DB, why not letting the DB do the calculation?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    pisumathu (05-20-2013)

  • #3
    New to the CF scene
    Join Date
    May 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Angry

    hi Dormilich,
    yes, they are coming from db. but there is 2 separate columns (date and time) how can we calculate ?

  • #4
    New to the CF scene
    Join Date
    May 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy

    Code:
    $time_me = $time ;  
    $time_me = explode(":",$time_me);
    $date_me = $date ;
    $date_me = explode("-",$date_me); 
    $target =  mktime($time_me[0], $time_me[1], $date_me[1], $date_me[2], $date_me[0]) ;
    
    $today = date('Y-m-d H:i') ;
    
    $difference =($today-$target) ;
    
    print $minuts = (int) ($difference/60);

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    if it were to be done in PHP, I’d first combine date and time to a datetime and then let strtotime() parse it.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Tags for this Thread

    Posting Permissions

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