• Can you tell me how to get datediff like “34 days, 7 hours, 22 minutes” (for example) , when I compare Date from Database nad current date (now() ) ? Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Bulgarin

    (@bulgarin)

    Thanks for this, but I’m new in php and I need more help, can you give me it? ??

    how to output a human readable time difference since the publish date of a post.

    try:

    add this code https://pastebin.com/wV8rm8Au to functions.php of your theme;

    in your template (in the loop), where you want to show the time difference, add:

    <?php
    $t1 = get_the_time('M j, Y G:i:s'); //gets the publish date of the post
    $t2 = date( 'M j, Y G:i:s'); //this is the reference; i.e. now
    echo human_date_diff($t1, $t2, 5); //output the time difference in human readable terms
    ?>
    Thread Starter Bulgarin

    (@bulgarin)

    Thank you, I’ll try it!

    Thread Starter Bulgarin

    (@bulgarin)

    I can’t get dates with

    <?php
    $t1 = get_the_time('M j, Y G:i:s'); //gets the publish date of the post
    $t2 = date( 'M j, Y G:i:s'); //this is the reference; i.e. now
    echo human_date_diff($t1, $t2, 5); //output the time difference in human readable terms
    ?>

    Can you give me examples?

    Can you give me examples?

    the code is the example.

    where have you added that code?
    – it would need to be added into the loop either in index.php or single.php

    what theme are you using?

    can you post a link to your site?

    Thread Starter Bulgarin

    (@bulgarin)

    I worked on localhost.
    And in $t1 = get_the_time(‘M j, Y G:i:s’); i must write
    $t1 = get_the_time(‘M j, Y G:i:s’,databasetime);
    or ?

    And in $t1 = get_the_time(‘M j, Y G:i:s’); i must write
    $t1 = get_the_time(‘M j, Y G:i:s’,databasetime);
    or ?

    no – the code should work without that; get_the_time() does not have two parameters.

    in which template file have you aded the code?

    can you paste the full code into a pastebin and post the link to it here?
    – how to –

    what theme are you using?

    when I compare Date from Database

    how are you getting the time from the datebase?
    is it the publish date of the post?

    Thread Starter Bulgarin

    (@bulgarin)

    how to post data from datatable row in t1?
    i used $row[myData]; to get after select-query, but how to post in t1?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show correct datediff’ is closed to new replies.