Wordpress post time minus 13 hours?
May 24, 2008 1:27 AM   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 answers 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, 2008


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, 2008


Response by poster: 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, 2008


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, 2008


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, 2008


Best answer: 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, 2008


Response by poster: 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, 2008


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, 2008


« Older Does anyone know a good printer that does NOT use...   |   How to get a baby to cope with new time zones? Newer »
This thread is closed to new comments.