Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When a user signs up on my site they have to select a date as part of resignation.

On their profile page I need to show a countdown to that date. Something simple like attached. How can I create this function?

enter image description here

share|improve this question
1  
I would start by searching the web for php subtracting dates. –  Milo Apr 2 '13 at 2:49
    
While you might be operating in a WP-environment, I fail to see what aspect of this is specific to that. Hence: How is this on-topic on this stack? –  Johannes Pille Apr 2 '13 at 7:38
add comment

1 Answer

You can use the following function to display it

<?php
function days_to_go(){
    $datetime1 = new DateTime('2013-3-2');//Pass resignation date as a parameter.
    $datetime2 = new DateTime(now);
    $interval = $datetime1->diff($datetime2);
    echo $interval->format('%a days to go');
}
?>

For more information on date_diff function see this page.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.