Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Denra.com

    (@denra)

    Hi @pietgolf,

    Can you please describe in details a little bit?

    Do you need to put epoch (timestamp) somewhere and produce date and time like May 23, 2020 20:28? Or something else?

    Thread Starter pietgolf

    (@pietgolf)

    I am using another plugin for showing the production of our solarpanels using shortcodes. One of these shortcodes is for showing the last update (date and time). This shortcode doesn’t actually show the date and time but the date/time in epoch format.

    I do need to get the correct date/time to show to our users. I do have 2 problems:
    1. I don’t know how to get the value of the epoch time in a variable or something like that that I can use as input for another shortcode/function. The plugin I am using has a shortcode to display epoch[last_update]
    2. I do need a way to get the correct date/time based on the epoch time (timestamp)

    It should be a great help if you can have a shortcode to show the correct date/time based on the epoch date/time and hopefully you can tell me how to get the epoch date/time as input for your shortcode.

    Plugin Author Denra.com

    (@denra)

    Hi again,

    There is no direct way to do this via our plugin, but you can put the code below in your functions.php in the child theme.

    function denra_last_update() {
        return date(get_option('date_format') . ' ' . get_option('time_format'), do_shortcode('[last_update]'));
    }
    add_shortcode('denra-last-update', 'denra_last_update');

    Then you can use the [denra-last-update] to display the date and time in the default readable format taken from the WordPress General Settings in the same way you have used the previous shortcode by now.

    If you wish to use another format, just remove the first part in the date function (to the comma) and replace it with any PHP date() function string that you like. Something like this:

    date('F j, Y H:i:s', do_shortcode('[last_update]'));

    Pease try it and let me know if it works.

    • This reply was modified 4 years, 6 months ago by Denra.com.
    • This reply was modified 4 years, 6 months ago by t-p.
    Thread Starter pietgolf

    (@pietgolf)

    Thank you for your help. It is displaying the date and time from the epoch of [last_update] but not the correct timezone. It is displaying the UTC date/time. But the good news is that I can now display the date and time using your shortcode.

    Using another format seems not to work for me but maybe I just don’t understand what you mean.

    Coudl you please change this line using the other format you mentioned?

    return date(get_option(‘date_format’) . ‘ ‘ . get_option(‘time_format’), do_shortcode(‘[last_update]’));

    It is for me a good exercise to get more familiar with php and shortcodes.

    Plugin Author Denra.com

    (@denra)

    Hi @pietgolf,

    What is the date and time format you wish to be displayed and in which timezone? Show me an example date and time format you would like to have r.e. October 12, 2020 – 10:44, 2020-10-12 10:44:15, or other.

    Plugin Author Denra.com

    (@denra)

    PS: Do you have the correct timezone set in the General Settings of WordPress?

    Thread Starter pietgolf

    (@pietgolf)

    I used also your shortcode [wpdts-date-time] on my page and this is showing 24 mei 2020 14:44. This is the format that I want. [denra_last_update] is showing ‘24 May 2020 12:38’ This should be ‘24 mei 14:38’. I am very gratefull that you take the time to help me.

    Plugin Author Denra.com

    (@denra)

    Do you have the correct timezone set in the General Settings of WordPress?

    Thread Starter pietgolf

    (@pietgolf)

    The timezone is set to ‘Amsterdam’

    Plugin Author Denra.com

    (@denra)

    It seems that the other plugin is using the wrong function to get the time from WordPress since they must use the current_time() function to get the initial timestamp with the timezone but they do not and they get the time without the timezone difference (you may let them know that). So you need to make a little hack now to get the correct timestamp until the time when/if they fix it.

    You can use the following code:

    function denra_last_update() {
        $hours_diff = 2;
        return date_i18n(
              get_option('date_format') . ' ' . get_option('time_format'), 
              intval(do_shortcode('[last_update]')) + ($hours_diff * 3600), false);
    }
    add_shortcode('denra-last-update', 'denra_last_update');

    Please let me know if it works.

    • This reply was modified 4 years, 6 months ago by Denra.com. Reason: Error in code fixed. Added bracket
    • This reply was modified 4 years, 6 months ago by Steven Stern (sterndata).
    Thread Starter pietgolf

    (@pietgolf)

    Using the code you send me

    function denra_last_update() {
    $hours_diff = 2;
    return date_i18n(
    get_option(‘date_format’) . ‘ ‘ . get_option(‘time_format’),
    intval(do_shortcode(‘[last_update]’) + ($hours_diff * 3600), false));
    }
    add_shortcode(‘denra-last-update’, ‘denra_last_update’);

    On my page no date or time but text [denra_last_update]

    Thread Starter pietgolf

    (@pietgolf)

    Can I send you a private message?

    Plugin Author Denra.com

    (@denra)

    Please email me to [email protected]

    Plugin Author Denra.com

    (@denra)

    I am glad that we helped you solve your issue.

    Please let me know if I can close this thread as solved.

    Thread Starter pietgolf

    (@pietgolf)

    Problem solved. Thank you

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘show date using epoch’ is closed to new replies.