Hi everyone

I have a PHP Class file (salat.times.php) that accepts a few User Inputs, one of which is a Date in the format dd-mm-yyyy. The date is used for a part of the class and is fine.

In another part of the class, there are a number of Time outputs with the format hh:mm.

Now, there two of these dates that I cannot seem to get precisely how I would like.

Time 1 is 05:17
Time 2 is 07:08

What I am trying to do is to have Time 1 equal to Time 2 minus 90 minutes, and obviously still be in the same hh:mm format. In the above example, Time 1 would become 05:38.

I have been experimenting with PHP Timestamps, but I'm finding it difficult converting things backwards and forwards.

For example if I create a timestamp manually, like

$timestamp = strtotime('06-10-2010 07:08:00');

I get a timestamp of 1286348880. And if I subtract 5400 (90 minutes worth of seconds), I end up with a timestamp of 1286343480.

But with this I am having two problems.

1. How can I get a Date variable into the strtotime() part?
2. How can I get the converted timestamp back into the time format hh:mm?

As usual, some really expert advice will be hugely appreciated.


$time_calc = date("H:i",$your_timestamp);

Hi and thanks chrishea

That solves the second problem just fine, But I still haven't been able to insert the $Datevar into the first part of $timestamp = strtotime('$datevar here! 07:08:00');.

I expect it will be as simple as your response, but it's completely elluding me at the moment.

Thanks again


To get a date format, again you need to convert the timestamp to date.

$datevar = date("d-m-Y H:i", $timestamp); // where $timestamp = "1286343480"
 // output will be 06-10-2010 05:38

check this below link for php date formats.
php date

strtotime("$date $time");

should work fine. Make sure that you use double quotes, not single.

Hi again

Well, I'm happy to say that the two answers supplied by chrishea were absolutely spot on.

So thanks very much chrishea for that.

And let's not forget paulrajj. His answer was an interesting variation on the first answer from chrishea.

Once again, thanks to all.