Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8037819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:02:19+00:00 2026-06-05T03:02:19+00:00

I am trying to add some php which show the time left for a

  • 0

I am trying to add some php which show the time left for a prodcut on my site, a little bit like an auction. It all displays well however when the time gets lower it shows 0d 34h 12m which means 0 days, 34 hours and 12 minutes, i was wondering if there was a way to get rid of the 0d bit if there are no days left a bit like this 34h 12m, it just makes it look better, the same for when there is no hours left and just minutes.

Here is the code that calculates the time left

$date = date('m/d/Y h:i:s', time());
$date3 = new DateTime($date);
$date4 = new DateTime($time_ending);
$interval_date = $date3->diff($date4);
$time_left = $interval_date->d."d ". $interval_date->h."h ". $interval_date->i."m "; 

Is there anyway i can do this?

Thanks for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:02:20+00:00Added an answer on June 5, 2026 at 3:02 am

    Yes, the shortest way would be

    $time_left = (($interval_date->d) ? $interval_date->d.'d ' : '')
               . (($interval_date->h) ? $interval_date->h.'h ' : '')
               . $interval_date->i.'m ';
    

    Briefly explained (cond) ? (stmA) : (stmB)
    equals if(cond){ stmA } else{ stmB }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make some Post Application which has to show messages like the
I'm trying to add some twitter funcionality to my website (php). I publish links
Hi I'm trying to add some another field to this php contact form I
Im trying to add some short file names to a Wise installer to fix
I'm trying to add some accessibility for screen readers into a Flash application, and
I'm trying to add some security to my ASP.NET 1.0 MVC app (VB), but
So I'm trying to add some ability to my project to allow user-defined properties
I am trying to add some additional logic to the 'Promoted to front page'
I am trying to add some shaders to my old OpenGL program that draws
I'm trying to add some HTML formatted text to Word using Office Interop. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.