Page 1 of 1

Show End date in (Ends: 9 Hours, 58 Mins +) Format

Posted: Tue Jun 27, 2006 11:29 pm
by eshban
Hi, can anybody tell me that how to get date this format (Ends: 9 Hours, 58 Mins +).

You can also view this from http://www.mobilityauction.com site

Posted: Wed Jun 28, 2006 12:26 am
by RobertGonzalez
You are going to need to do some time math. Basically subtract the end time of the listing from what time it is now and convert it to hours, minutes and seconds, then display each.

Posted: Wed Jun 28, 2006 1:23 am
by eshban
can you send me a code, it helps me a lot. Becoz i am still confused from your reply.

Posted: Wed Jun 28, 2006 1:34 am
by RobertGonzalez
I won't do it for you (for free anyway), but I, along with others here, will certainly help you.

The first thing you are going to need to know is what time it is now. Then you are going to need to know what time the listing ends. Then you are going to need to get the two date/times in a format that will allow you to subtract the later from the earlier. Then you will need to take that value, and convert it into the parts of time you want (Hours, Minutes and Seconds). Then echo those out.

Start with that and see what you can come up with. If you have problems, post your code and the community will help you sort it out. But try first.

Posted: Wed Jun 28, 2006 2:02 am
by aerodromoi
Here's a basic example for a countdown.
Shouldn't be too hard to do the math to split the output into days, hrs and minutes... ;)

Code: Select all

<?php
function countdown($dbdate){
  $dbtime = strtotime($dbdate);
  $ctime  = date("U");
  $tdiff  = $dbtime - $ctime;
  if($tdiff>0){
    $difference = $tdiff." secs remaining.";
  }
  else{
    $difference = "Sorry, time's up!";
  }
  return $difference;
}

$dbdate = "June 29, 2006 19:07:13";
print (countdown($dbdate));
?>
aerodromoi

Posted: Wed Jun 28, 2006 2:04 am
by eshban
Here is the code :

Code: Select all

$currentdate = time();       // current time
$expirydate = time() + (5 * 24 * 60 * 60);   //Add 5 days to the cuurent date
now i want to display an item w.r.t current time. if current time is less than the expiry time stored in database current date then item will be shown and end date of that item will b displayed in follwing format :

e.g; 4 days, 8 hours, 45 Mins // output

Posted: Wed Jun 28, 2006 2:17 am
by aerodromoi
eshban wrote:Here is the code :

Code: Select all

$currentdate = time();       // current time
$expirydate = time() + (5 * 24 * 60 * 60);   //Add 5 days to the cuurent date
now i want to display an item w.r.t current time. if current time is less than the expiry time stored in database current date then item will be shown and end date of that item will b displayed in follwing format :

e.g; 4 days, 8 hours, 45 Mins // output
If you're using a timestamp as the expiry date, you won't need strtotime in my function.
Just as a hint: You might want to take a look at floor for splitting the remaining time...

aerodromoi

Posted: Wed Jun 28, 2006 7:57 am
by feyd
look for printf's Code Snippet that returns the time broken down.