Advertise here: Contact FM.


Wordpress post time minus 13 hours?
May 24, 2008 1:27 AM   RSS feed for this thread Subscribe

I need Wordpress to display the_time as well as the_time - X.

I maintain a blog that runs on Japan time. It's easy to have the template contain a call to the_time and it displays just fine. I want to change my template so that the time fields would show "2:00 PM (1:00 PM EST)".

I've tried many variants like:

the_time('g:i') + 1
the_time('g'+1)
the_time('g')+1

Nothing seems to display what I want. I've googled it, and there are tons of hits on how to use the PHP time() function, but this seems different to me. This really has nothing to do with the current server time, I'm just transforming the result of a database call.
posted by mysterious1der to computers & internet (8 comments total) 1 user marked this as a favorite
date('g:i',strtotime(the_time('H:i:s')+3600)
posted by sycophant at 1:48 AM on May 24


Must learn to proof-read... Missing a closing bracket:
date('g:i',strtotime(the_time('H:i:s'))+3600)

PHP date function formats the result of strtotime's parsed time from Wordpress' the_time().

If that doesn't work, try adding the date to the Wordpress time function:
the_time("Y-m-d H:i:s")
posted by sycophant at 1:50 AM on May 24


Hey sycophant, thanks for the response.

Here's my current timestamp:

?php the_time('F jS, Y - g:i A') ?> by ?php the_author() ?

to which I appended your code above, so that now it looks like

?php the_time('F jS, Y - g:i A') ?> by ?php the_author() ? ?php date('g:i',strtotime(the_time('H:i:s'))+3600) ?

minus the appropriate <>'s to pass the AskMeFi filter.

The above all renders as:

May 24th, 2008 - 11:59 PM by Author
23:59:45

So it seems to not actually be evaluating the mathematical operation (which I could never make it do either). Thanks in advance for your time. Am I missing something?
posted by mysterious1der at 12:11 PM on May 24


Wordpress template function echo to screen (which is somewhat stupid, but saves templaters from having to learn 'print', I guess).

You want to use "get_the_time" which returns the time in place of 'the_time' which echoes it to the screen.

Also, I'd go 'g:ia' on the date format, but that's because I like am/pm.
posted by fishfucker at 1:26 PM on May 24


wow, that typo made the first sentence hard to parse:

"Wordpress template functions echo to the screen."

FWIW, I have tested this on a wordpress install with get_the_time and it worked fine.

posted by fishfucker at 1:28 PM on May 24


er, also -13 hours would mean using -46800, not +3600.

Actually, you probably want this:


<?php print date('g:ia',get_post_time()-46800);?>


Which will allow you to properly handle dates as well as time, if you like, and avoids converting to a string format just to convert back to epoch time.
posted by fishfucker at 1:38 PM on May 24


Thanks fishfucker, that worked perfectly. 2 questions:

1) Is the protocol for me to mark all your answers as best, or just the last one?

2) How were you able to enter the php code and not have AskMeFi strip it out?
posted by mysterious1der at 5:19 PM on May 24


1) whichever one worked best, I guess. It's really up to you.
2) Using HTML entities: in this case, '&lt;' instead of an '<', and '&gt;' instead of a '>'
posted by fishfucker at 7:45 PM on May 24


« Older Does anyone know a good multi-...   |   How should I reconcile my baby... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Where does the day go? June 9, 2008
Now for a FarAway() function, and we can code up a... February 1, 2008
I'm trying to find the title of an old PC game November 27, 2007
Recommendations for Real Time Strategy games November 3, 2007
How can I use PHP to display a MYSQL datetime... November 28, 2006