Title: Compare two dates
Last modified: August 18, 2016

---

# Compare two dates

 *  [hapaxlegomen](https://wordpress.org/support/users/hapaxlegomen/)
 * (@hapaxlegomen)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/compare-two-dates/)
 * For lot of reasons (too long to explain in fact) I have several dates by post
   in the DB (add by myself).
 * So post_date, post_datedead, post_datefuture, post_datepast. I have made functions
   in a plugin by copying template function “the_date()”. Everything works.
 * My problem is I need to compare these dates, to know for example how much days
   there are between the 15/02/2005 and the 18/03/2005, and catch it in a variable…
 * I have made some mysql functions like “the_datepast_mysql()”
 * see :
 * function the_datepast_mysql() {
    global $post; echo $post->post_datedebut; }
 * It works. And another function to compare :
 * see :
 * function numberofdays($mmstart, $mmend) {
 *  $tDeb = explode(“-“, $mmstart);
    $tFin = explode(“-“, $mmend);
 *  $diff = mktime(0,0,0, $tFin[1], $tFin[2], $tFin[0]) –
    mktime(0,0,0, $tDeb[1],
   $tDeb[2], $tDeb[0]);
 *  return(($diff / 86400)+1);
 * }
 * But I can’t catch a result ! … ? I can’t understand why and it’s perhaps under
   my nose but I can’t understand why and it’s perhaps under my nose but I can’t
   understand why and it’s perhaps under my nose but I can’t understand why and 
   it’s perhaps under my nose but I can’t understand why… horrible.

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

 *  [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/compare-two-dates/#post-272293)
 * You’re aware `return` doesn’t output anything, right?
 *  Thread Starter [hapaxlegomen](https://wordpress.org/support/users/hapaxlegomen/)
 * (@hapaxlegomen)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/compare-two-dates/#post-272296)
 * Euh No. My only knowledge is to copy paste functions everywhere and try to make
   them work. So lot of things are chinese to me but some are understood.
 * What must I do to make this give me my number of days ??
    (Thanks for help)
 *  [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [20 years, 7 months ago](https://wordpress.org/support/topic/compare-two-dates/#post-272384)
 * `return` doesn’t output anything, it only returns the value. Replace `return`
   with `echo`. Oh, and you don’t need parenthesis either:
 * `echo ($diff / 86400)+1;`
 * And may I just suggest [this plugin](http://binarybonsai.com/wordpress/time-since/)
   instead? You can see it in action on [my blog](http://www.viper007bond.com/archives/2005/10/11/new-version-of-the-steam-client/).

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

The topic ‘Compare two dates’ is closed to new replies.

## Tags

 * [dates](https://wordpress.org/support/topic-tag/dates/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * Last activity: [20 years, 7 months ago](https://wordpress.org/support/topic/compare-two-dates/#post-272384)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
