/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] How do I calculate how many days ago a post was posted?

In my WordPress database, the time when a post was posted is recorded in the format Y-m-d H:i:s

How do I find out how many days ago a post was posted? Thanks in advance.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 16.2010 — It's probably easiest to do it in the database query, as it's almost certainly a datetime type field, so you could use the MySQL DATEDIFF() function, along with CURDATE() for the first parameter.
Copy linkTweet thisAlerts:
@narutodude000authorOct 16.2010 — I got $query="SELECT ID, DATEDIFF(CURDATE(),post_date), post_author, ...", then the outputed resource is transformed into an array. I can access fields by using $post['comment_count'], $post['post_author'], etc. How do I access the value of DATEDIFF(CURDATE(),post_date)?
Copy linkTweet thisAlerts:
@narutodude000authorOct 16.2010 — Nevermind, I got it using [CODE]DATEDIFF(CURDATE(),post_date) as post_age[/CODE]

Thanks!
×

Success!

Help @narutodude000 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Marika,
tipped: article
amount: 1000 SATS,

tipper: @hatem774,
tipped: article
amount: 1 SATS,

tipper: @nearjob,
tipped: article
amount: 1000 SATS,
)...