Hi I am facing problem for getting difference between hours and miuntes

I have two variables

$one=9:30 am;    $two=6:30 pm;



                 How to get difference in Hours and minutes

Recommended Answers

Hi,

use the DateTime library, in particular look at the diff() method. For example:

<?php

    $one = '09:30AM';
    $two = '06:30PM';

    $dtime_1 = new Datetime($one);
    $dtime_2 = new Datetime($two);

    $diff = $dtime_1->diff($dtime_2);
    echo $diff->format('%H:%I');

Will print 09:00. More info here:

Jump to Post

All 2 Replies

Excellent its working

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.