Giacomo
Giacomo

Reputation: 1

Adding a fixed value to an existing function

I need to adjust the code below that displays a simplre Time to a "Start time - End Time", example: "12:00" should be "12:00- 14:00". Just adding 2 hours more to the first time.

Original Code:

foreach ( $blocks as $block ) {
        $block_html .= '<li class="block" data-block="' . esc_attr( date( 'Hi', $block ) ) . '"><a href="#" data-value="' . date( 'G:i', $block ) . '">' . date_i18n( get_option( 'time_format' ), $block ) . '</a></li>';
    }

    return $block_html;

Should be something like:

foreach ( $blocks as $block ) {
        $block_html .= '<li class="block" data-block="' . esc_attr( date( 'Hi', $block ) ) . '"><a href="#" data-value="' . date( 'G:i', $block ) . '">' . date_i18n( get_option( 'time_format' ), $block ) . ' - ' . /* HERE GOES THE END TIME*/ . '</a></li>';
    }

    return $block_html;

Thank you for any incoming help.

Upvotes: 0

Views: 15

Answers (1)

vaso123
vaso123

Reputation: 12391

I assume, your $block contains a unix timestamp. If yes, try this:

echo date( 'H:i', $block ) ." - " . date( 'H:i', $block + (60*60*2) );

You can use the mktime function too.

Upvotes: 1

Related Questions