W
W
WebforSelf2020-11-16 22:34:15
PHP
WebforSelf, 2020-11-16 22:34:15

How to make time intervals condition Smarty or PHP?

The question of such a plan, you need to display the text depending on the time intervals.

Ideally, of course, on smart, well, or on php I

went first by the template engine

Intervals

{$time_start_1 = '0:00'}   
  {$time_finish_1 = '9:59'} 

  {$time_start_2 = '10:00'}   
  {$time_finish_2 = '11:59'}

  {$time_start_3 = '12:00'}   
  {$time_finish_3 = '13:59'}

  {$time_start_4 = '14:00'}   
  {$time_finish_4 = '16:29'}

  {$time_start_5 = '16:30'}   
  {$time_finish_5 = '23:59'}


Conditions by time (range) at what time what to show
{if $smarty.now|date_format:"%H:%M" >= $time_start_1 && $smarty.now|date_format:"%H:%M" <= $time_finish_1}
{$day_pvz = 'сегодня'}
{$time_pvz = 'до 12:00'}
{elseif $smarty.now|date_format:"%H:%M" >= $time_start_2 && $smarty.now|date_format:"%H:%M" <= $time_finish_2}
{$day_pvz = 'сегодня'}
{$time_pvz = 'до 14:00'}
{elseif $smarty.now|date_format:"%H:%M" >= $time_start_3 && $smarty.now|date_format:"%H:%M" <= $time_finish_3}
{$day_pvz = 'сегодня'}
{$time_pvz = 'до 16:30'}
{elseif $smarty.now|date_format:"%H:%M" >= $time_start_4 && $smarty.now|date_format:"%H:%M" <= $time_finish_4}
{$day_pvz = 'сегодня'}
{$time_pvz = 'до 18:00'}
{elseif $smarty.now|date_format:"%H:%M" >= $time_start_5 && $smarty.now|date_format:"%H:%M" <= $time_finish_5}
{$day_pvz = 'завтра'}
{$time_pvz = 'до 12:00'}
{/if}


Now, in the end, 22:30 and should display "tomorrow until 12 00") and displays the first condition "today until 12 00.

If you can explain in PHP, I will be grateful, because in principle I didn’t focus on smart, it’s just convenient through the template engine .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman PHP, 2020-11-16
@WebforSelf

<?php

var_dump('22:30' >= '0:00' && '22:30' <= '9:59');
var_dump('22:30' >= '00:00' && '22:30' <= '09:59');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question