Skip to content

Instantly share code, notes, and snippets.

@stansidel
Created May 13, 2015 09:23
Show Gist options
  • Save stansidel/951be1b233b4accb4513 to your computer and use it in GitHub Desktop.
Save stansidel/951be1b233b4accb4513 to your computer and use it in GitHub Desktop.
Функция для форматирования поля отбора от текущей даты на N дней назад для Битрикс (Bitrix)
<?php
function getNDaysBack($daysCount, $php_format = false) {
// php_format должен быть равен 'Y-m-d' для выборки по свойствам CIBlockElement::GetList
// в остальных случаях, например, для CSaleOrder::GetList этот параметр не нужно указывать
if($php_format === false) {
// получим полный формат сайта
$site_format = CSite::GetDateFormat("FULL");
global $DB;
// переведем формат сайта в формат PHP
$php_format = $DB->DateFormatToPHP($site_format);
}
// сейчас
$today = time();
// кол-во секунд в сутках
$day = 86400;
// кол-во секунд в N сутках
$last_n_day = $today - ($day*$daysCount);
// выведем дату, которая была N дней назад
return date($php_format, $last_n_day);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment