March 24, 2012

Calculate time left from specific datetime in php

Question by user1286499

may I know how do I calculate time left from specific datetime in php?

Example I want user can request a new confirmation code after 30 minute if already requested.

$request_date = '2012-03-24 13:03:17';
$please_wait  = '30 minutes';

How do I calculate the time left?

Answer by safarov

Time left for new confirmation code:

$request_date = '2012-03-24 13:03:17';
$please_wait  = '30 minutes';
$future_time = strtotime("+" . $please_wait, strtotime($request_date));
$time_left = $future_time - time(); //seconds left

Answer by Starx

Calculate the requested timestamp and sustract with currect time stamp

Solution:

$future = strtotime($request_date)+1800; // 1800 is 30 minutes
echo date("i", $future-time()); //this is the remaining minutes

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!