• LCT

    (@lct)


    Hi,

    I’ve got a problem using that command line:
    <?php echo ‘Il y a ‘ . human_time_diff(get_the_time(‘U’), current_time(‘timestamp’)) ; ?>

    As you can see on that page displaying all 2000 year posts, the relative dates for articles published between june and december are OK (20 years ago) but they are wrong for all articles published between january and may (21 years ago)! Why?

    Thanks for your help

    • This topic was modified 4 years ago by LCT.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I think it’s a rounding artifact. 18 May 2000 is a bit over 20.5 years ago, so rounded to 21 years. 7 June 2000 is a bit less than 20.5 years, so 20 is shown.

    Thread Starter LCT

    (@lct)

    Thanks for your reply. Do you know a solution to fix that?

    Moderator bcworkz

    (@bcworkz)

    If you want the integer difference between years, that’s exactly what your code should do ??
    <?php echo current_time('Y') - get_the_time('Y'); ?>

    This is a little naughty coding-wise because we’re actually performing maths on string values. Since PHP is loosely typed, we can get away with it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problème dates relatives fonction human_time’ is closed to new replies.