Title: Set a simple countdown timer using custom fields
Last modified: August 19, 2016

---

# Set a simple countdown timer using custom fields

 *  [Rob Cubbon](https://wordpress.org/support/users/robcub/)
 * (@robcub)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/set-a-simple-countdown-timer-using-custom-fields/)
 * I’ve found a great little bit of PHP that will calculate and display how many
   days there are left until a certain date in the future.
 *     ```
       <?
         $day   = 11    ; // Day of the countdown
         $month = 3;      // Month of the countdown
         $year  = 2011;   // Year of the countdown
         $hour  = 23;     // Hour of the day (east coast time)
   
         $calculation = ((mktime ($hour,0,0,$month,$day,$year) - time(void))/3600);
         $hours = (int)$calculation;
         $days  = (int)($hours/24);
       ?>
   
       <p> <?=$days?> days</span> left to go</p>
       ```
   
 * Thank you, Joe Crawford [http://lab.artlung.com/countdown/](http://lab.artlung.com/countdown/)
 * My problem is I want to be able to specify the date that is being counted down
   to using Custom Fields specific to a particular post.
 * So I’ll have 3 custom field Names called “countdown-date”, “countdown-month” 
   and “countdown-year” and get them to spit out the values in the PHP above.
 * So far my miserable PHP skills have come up with stuff like:
 *     ```
       <?
         $day   = <?php get_post_meta($post->ID, 'countdown-date', true); ?>    ; // Day of the countdown
         $month = 3;      // Month of the countdown
         $year  = 2011;   // Year of the countdown
         $hour  = 23;     // Hour of the day (east coast time)
       ...
       ```
   
 * But these give me error messages. I hope someone would know how to do this.
 * This is within the loop.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/set-a-simple-countdown-timer-using-custom-fields/#post-1941988)
 * the error message is because this is already php code (starting with the php 
   short tag `<?` )and you are adding a new php tag;
 * try:
 *     ```
       <?php
         $day   = get_post_meta($post->ID, 'countdown-date', true); // Day of the countdown
         $month = 3;      // Month of the countdown
       ```
   
 * etc. (changed the php short tag to a full one)
 *  Thread Starter [Rob Cubbon](https://wordpress.org/support/users/robcub/)
 * (@robcub)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/set-a-simple-countdown-timer-using-custom-fields/#post-1942029)
 * Thank you so much, alchymyth, that works like a dream.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Set a simple countdown timer using custom fields’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Rob Cubbon](https://wordpress.org/support/users/robcub/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/set-a-simple-countdown-timer-using-custom-fields/#post-1942029)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
