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

  • SEARCH
  • Home
  • 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 9016905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:07:36+00:00 2026-06-16T04:07:36+00:00

I have a countdown function that (in part) returns the time left until a

  • 0

I have a countdown function that (in part) returns the “time left” until a given date/time. The value is returned as a DateInterval object and is calculated using the diff method.

//calculate countdown time
$time_diff = $countdown->diff($current);

Given that $time_diff is a DateInterval object, how would I do this?

if ($time_diff > 60) {

    //do stuff

}

I know the code above doesn’t work, but how can/should I evaluate the equivalent condition (“more than 60 sec left in this DateInterval object”)?

The problem is that the script used to return the “time left” as a Unix timestamp integer, and the function is utilized in a more procedural manner by a wide array of scripts in my system.

Thank you in advance for any helpful suggestions.

  • 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-16T04:07:37+00:00Added an answer on June 16, 2026 at 4:07 am

    Because it is not possible to use the format() method on a DateInterval object to get directly the total amount of remaining time in seconds, I ended up adding a helper in my function to return the “time left” as a Unix timestamp along with the DateInterval object.

    //calculate unix timetamps
    $current_ts = time();
    $countdown_ts = $countdown->getTimestamp();
    $timestamp_diff = ($current_ts < $countdown_ts) ? ($countdown_ts - $current_ts) : 0;
    

    Hope this is useful to others.

    PS. Stackoverflow is awesome.

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

Sidebar

Related Questions

I have a function that redirects to a countdown while our system is offline,
I have a function that displays a countdown next to a text field for
I have written a function that is a countdown timer. I want to print
I have the following script: Timer=0; function countdown(auctionid){ var auctions; var divs; Timer=Timer+1; if((Timer%10==0)||(Timer==1)){
In my android project, I have a countdown that randomizes a boolean for an
I have got a piece of code, that should countdown some number (in this
have written this little class, which generates a UUID every time an object of
I have this countdown script wrapped as an object located in a separate file
In my web page, I have a countdown timer using Javascript's setTimeout() . function
I have a timer that counts down every second. It works great until the

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.