Title: WordPress Date function woe
Last modified: August 18, 2016

---

# WordPress Date function woe

 *  [david](https://wordpress.org/support/users/david/)
 * (@david)
 * [21 years, 11 months ago](https://wordpress.org/support/topic/wordpress-date-function-woe/)
 * Can anyone help me to sort out the following code. I would like posts from today
   to be datestamped “today”,. and previous posts to take a date stamp. I wrote 
   the following code which of course doesn’t work.
    ` <?php $today = date("dmy");
   $published = the_time("dmy"); if($today == $published){?>Today <?}else{?> <?the_time("
   l")?>, the <?the_time("j")?><?the_time("S")?> of <?the_time("F")?> <?}?>  I am
   going ka ka koo koo. If [WP’s loop](http://wiki.wordpress.org/TheLoop/Post) has
   a variable with just a clean date stamp I think I would use that…but it returns
   a date and a time, and I don’t know how to just strip out the date from that.
   Can anyone come with a solution? I know the root of my problem comes from trying
   to embed WP functions in my own PHP code. I also think it would be nice to have
   the ability to use relative date/time stamp posts in the same way that textpattern
   does (for ex. “posted 2 hours ago”, “posted 4 days ago”, etc) Maybe there are
   some plug-ins which I just haven’t located yet.

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

 *  [codergurl](https://wordpress.org/support/users/codergurl/)
 * (@codergurl)
 * [21 years, 11 months ago](https://wordpress.org/support/topic/wordpress-date-function-woe/#post-65808)
 * `<?php
    $today = date('Y-m-d'); $pubdate = explode(' ', $post->post_date); $pubdate
   = $pubdate[0]; if ($pubdate == $today) { echo "Today"; } else { the_time('l\,\
   t\h\e jS \o\f F'); } ?> I had written a hack/plugin to get the years, months,
   days, etc.., since a while back, and someone editted it. Search in the [wiki](http://wiki.wordpress.org).
 *  Thread Starter [david](https://wordpress.org/support/users/david/)
 * (@david)
 * [21 years, 11 months ago](https://wordpress.org/support/topic/wordpress-date-function-woe/#post-65841)
 * Thanks, the code you wrote is perfect. And the plugin can be located here, should
   anyone else be interested.
    [http://manalang.com/archives/2004/05/24/wordpress-plugin-time-since](http://manalang.com/archives/2004/05/24/wordpress-plugin-time-since)

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

The topic ‘WordPress Date function woe’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [david](https://wordpress.org/support/users/david/)
 * Last activity: [21 years, 11 months ago](https://wordpress.org/support/topic/wordpress-date-function-woe/#post-65841)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
