Jump to content
  • 0

Отнять от даты/времени несколько часов, на PHP


korjik
 Share

Question

Всем привет! Повстречал вот такой вот скрипт, а как отнять от выводимого времени несколько часов (например 3) не знаю..


function date_view($date_input, $time = false) {
$monthes = array('', 'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');
$date = strtotime($date_input);
if ($time) $time = ' в G:i';
else $time = '';
if (date('Y') == date('Y', $date)) {
if (date('z') == date('z', $date)) {
$result_date = date('Сегодня'.$time, $date);
} elseif (date('z') == date('z', mktime(0, 0, 0, date('n', $date), date('j', $date) + 1, date('Y', $date)))) {
$result_date = date('Вчера'.$time, $date);
} elseif (date('z') == date('z', mktime(0, 0, 0, date('n', $date), date('j', $date) - 1, date('Y', $date)))) {
$result_date = date('Завтра'.$time, $date);
}
if(isset($result_date)) return $result_date;
}
$month = $monthes[date('n',$date)];
if (date('Y') != date('Y', $date)) $year = 'Y г.';
else $year = '';
$result_date = date('j '.$month.' '.$year.$time, $date);
return $result_date;
}

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy