Title: Extract the_time() as string
Last modified: August 20, 2016

---

# Extract the_time() as string

 *  [magicwings](https://wordpress.org/support/users/magicwings/)
 * (@magicwings)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/extract-the_time-as-string/)
 * Hey all,
 * Basically I’m trying to get a string attached to `the_time('F j, Y')`.
 * What’s going wrong?
 * My code is this (for example):
 * `<?php $my_post_date = the_time('F j, Y') ?>`
 * BUT on ANY mention of the function the_time(), it will ECHO what I’ve written!
 * This means that the above actually APPEARS on the page saying
 * `October 9, 2011`
 * despite me just trying to declare it as part of the `$my_post_date` string.
 * So how do I make a string that has the posts’ date? Any ideas?

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

 *  [peredur](https://wordpress.org/support/users/peredur/)
 * (@peredur)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/extract-the_time-as-string/#post-2338618)
 * See [http://codex.wordpress.org/Function_Reference/the_time](http://codex.wordpress.org/Function_Reference/the_time):
 * > Codex
   > Function Reference/the_time
   > Displays the time of the current post. This tag must be used within The Loop.
 * The operative word here is “Displays”.
 * Use the PHP [date()](http://php.net/manual/en/function.date.php) function or 
   one of its many friends.
 * HTH
 * PAE
 *  Thread Starter [magicwings](https://wordpress.org/support/users/magicwings/)
 * (@magicwings)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/extract-the_time-as-string/#post-2338619)
 * Ah, but I’m trying to get the date of the current post within the loop, and compare
   it with today’s date.
 * How’s that possible?
 *  [peredur](https://wordpress.org/support/users/peredur/)
 * (@peredur)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/extract-the_time-as-string/#post-2338623)
 * [http://codex.wordpress.org/Function_Reference/get_the_date](http://codex.wordpress.org/Function_Reference/get_the_date)
 * Cheers
 * PAE
 *  Thread Starter [magicwings](https://wordpress.org/support/users/magicwings/)
 * (@magicwings)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/extract-the_time-as-string/#post-2338710)
 * Awesome, thanks, worked a charm 🙂
    Ben

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

The topic ‘Extract the_time() as string’ is closed to new replies.

## Tags

 * [date](https://wordpress.org/support/topic-tag/date/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [string](https://wordpress.org/support/topic-tag/string/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [magicwings](https://wordpress.org/support/users/magicwings/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/extract-the_time-as-string/#post-2338710)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
