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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

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

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

Post by eshban »

can you send me a code, it helps me a lot. Becoz i am still confused from your reply.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post 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
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

Post 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
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

look for printf's Code Snippet that returns the time broken down.
Post Reply