Господа, подскажите такой как прибавить к дате 3 года.
Вьюхой вывожу поля, в т.ч. поле дата. Темизировал поле дата - в файле views-view-field--att--field-ex-date.tpl.php пишу:
Выдает результат: Выдан: 30.06.2006 Действителен до: 28.05.2014
т.е. прибавляет 3 года к текущей дате.
Подскажите че нибудь
Комментарии
Не нужно в $output записывать текущую дату.
А как?
echo $new_date;
Так получается Действителен до: 01.01.1973
Я попробовал твой код - работает.
Судя по 01.01.1973 - прибавка идет, а вот $output наверное неправильно конвертируется, потому что 01.01.1970 - это дефолтный временной штам
Я понимаю, что прибавка идет, да тут еще Drupal 7, я PHP не знаю
В самой базе дата в таком формате у меня: 2006-06-30T00:00:00
может тут надо копать?
А какой конкретно код у тебя сработал? Я пробовал на разных сайтах - везде 73 год. И на 6 и 7 друпале
$new_date = date('d.m.Y', strtotime('+3 year', strtotime('2000-01-01T00:00')));
echo $new_date;
?>
<?php
$new_date = date('d.m.Y', strtotime('+3 year', strtotime('01.01.2000')));
echo $new_date;
?>
Так оно и у меня работает, но если подставлять вместо готовой даты $output
$new_date = date('d.m.Y', strtotime('+3 year', strtotime($output)));
echo $new_date;
?>
Он его игнорирует вообще и прибавляет к 70-му году: 01.01.1973
А в $output у тебя что? Дата или строка? Если дата, может не надо ее через strtotime
Дата из cck поля (модуль date) формат вывода делал разный и краткий и полный и даже unix сделал - U - все одинаково. В $output естественно то, что настроил во view
Пробовал и так:
Ничего не получается
Неужели никто не сталкивался?
Пробую еще код:
$date = strtotime($output);
$end_date = date('d.m.Y', mktime(0,0,0,date('m',$date),date('d',$date),date('Y',$date)+5));
echo $end_date;
?>
Выдает 01.01.1975
Если $date = $output;
Выдает 30.11.2004
откуда эта дата взялась вообще не понятно
Добавьте в своем шаблоне print_r($variables); и покажите результат. А там подскажем
http://www.php.net/manual/ru/datetime.add.php
<?php$date = date_create('2000-01-01');
date_add($date, date_interval_create_from_date_string('10 days'));
echo date_format($date, 'Y-m-d');?>
подставьте вместо '2000-01-01' $output в таком формате.
п.с. php >= 5.3.0, если у вас меньше, см. http://www.php.net/manual/ru/datetime.modify.php
Это в ядре ... Все страницы, которые генерирует движок(админка, авторизация, модули и т.д.) если попытаться вывести дату будут давать такие цифры. Т.е. даты нет там, куда вы пытаетесь её вывести.
У себя сделал так :
<?php if ($node->type != 'service_core' && $node->type != 'poll' && $node->type != '') { ?>
<?php print format_date($node->created, 'custom', "D, m/d/Y"); ?>
<?php } ?>
в type пишете все типы, какие есть.
====
Упс. Для 7 не знаю как, но подозреваю, что цифра такая оттуда же растёт
Выдает ошибку: 'Exception: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'))
ORDER BY node_created DESC\' at line 2'
В 7-ке это почему-то не срабатывает, уже пробовал
date_add($date, date_interval_create_from_date_string('10 days'));
echo date_format($date, 'Y-m-d');?>
С этим кодом вылетает в белый экран. PHP 5.2.9-2
Array ( [vid] => 291 [uid] => 1 [title] => 19714 [log] => Created by FeedsNodeProcessor [status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [nid] => 291 [type] => attestat [language] => und [created] => 1306602719 [changed] => 1306602719 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1306602719 [revision_uid] => 1 [field_att_num] => Array ( [und] => Array ( [0] => Array ( [value] => 017785 [format] => plain_text [safe_value] => 017785 ) ) ) [field_w_id] => Array ( [und] => Array ( [0] => Array ( [value] => 9 [format] => plain_text [safe_value] => 9 ) ) ) [field_zav_id] => Array ( [und] => Array ( [0] => Array ( [value] => 21811 [format] => plain_text [safe_value] => 21811 ) ) ) [field_ex_date] => Array ( [und] => Array ( [0] => Array ( [value] => 2006-06-30T00:00:00 [timezone] => Europe/Helsinki [timezone_db] => Europe/Helsinki [date_type] => date ) ) ) [field_cand_id] => Array ( [und] => Array ( [0] => Array ( [value] => 17089 [format] => plain_text [safe_value] => 17089 ) ) ) [field_att_true] => Array ( [und] => Array ( [0] => Array ( [value] => 0 [format] => plain_text [safe_value] => 0 ) ) ) [field_w_iindex] => Array ( [und] => Array ( [0] => Array ( [value] => СТ [format] => plain_text [safe_value] => СТ ) ) ) [field_w_service] => Array ( [und] => Array ( [0] => Array ( [value] => мастера[summary] => [format] => plain_text [safe_value] =>
мастера
[safe_summary] => ) ) ) [field_cand_famely] => Array ( [und] => Array ( [0] => Array ( [value] => ФИЛ [format] => plain_text [safe_value] => ФИЛ ) ) ) [field_cand_name] => Array ( [und] => Array ( [0] => Array ( [value] => Анатолий [format] => plain_text [safe_value] => Анатолий ) ) ) [field_cand_oldname] => Array ( [und] => Array ( [0] => Array ( [value] => Анатольевич [format] => plain_text [safe_value] => Анатольевич ) ) ) [field_att_note] => Array ( [und] => Array ( [0] => Array ( [value] => [format] => plain_text [safe_value] => ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1306602719 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [print_display] => 0 [print_display_comment] => 0 [print_display_urllist] => 0 [name] => admin [picture] => 0 [data] => [print_mail_display] => 0 [print_mail_display_comment] => 0 [print_mail_display_urllist] => 0 [uri] => Array ( [path] => node/291 [options] => Array ( [entity_type] => node [entity] => stdClass Object ( [vid] => 291 [uid] => 1 [title] => 19714 [log] => Created by FeedsNodeProcessor [status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [nid] => 291 [type] => attestat [language] => und [created] => 1306602719 [changed] => 1306602719 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1306602719 [revision_uid] => 1 [field_att_num] => Array ( [und] => Array ( [0] => Array ( [value] => 017785 [format] => plain_text [safe_value] => 017785 ) ) ) [field_w_id] => Array ( [und] => Array ( [0] => Array ( [value] => 9 [format] => plain_text [safe_value] => 9 ) ) ) [field_zav_id] => Array ( [und] => Array ( [0] => Array ( [value] => 21811 [format] => plain_text [safe_value] => 21811 ) ) ) [field_ex_date] => Array ( [und] => Array ( [0] => Array ( [value] => 2006-06-30T00:00:00 [timezone] => Europe/Helsinki [timezone_db] => Europe/Helsinki [date_type] => date ) ) ) [field_cand_id] => Array ( [und] => Array ( [0] => Array ( [value] => 17089 [format] => plain_text [safe_value] => 17089 ) ) ) [field_att_true] => Array ( [und] => Array ( [0] => Array ( [value] => 0 [format] => plain_text [safe_value] => 0 ) ) ) [field_w_iindex] => Array ( [und] => Array ( [0] => Array ( [value] => СТ [format] => plain_text [safe_value] => СТ ) ) ) [field_w_service] => Array ( [und] => Array ( [0] => Array ( [value] => мастера [summary] => [format] => plain_text [safe_value] =>
мастера
[safe_summary] => ) ) ) [field_cand_famely] => Array ( [und] => Array ( [0] => Array ( [value] => ФИЛ [format] => plain_text [safe_value] => ФИЛ ) ) ) [field_cand_name] => Array ( [und] => Array ( [0] => Array ( [value] => Анатолий [format] => plain_text [safe_value] => Анатолий ) ) ) [field_cand_oldname] => Array ( [und] => Array ( [0] => Array ( [value] => Анатольевич [format] => plain_text [safe_value] => Анатольевич ) ) ) [field_att_note] => Array ( [und] => Array ( [0] => Array ( [value] => [format] => plain_text [safe_value] => ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1306602719 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [print_display] => 0 [print_display_comment] => 0 [print_display_urllist] => 0 [name] => admin [picture] => 0 [data] => [print_mail_display] => 0 [print_mail_display_comment] => 0 [print_mail_display_urllist] => 0 [uri] => Array *RECURSION* [entity_view_prepared] => 1 ) ) ) [entity_view_prepared] => 1 [elements] => Array ( [#pre_render] => Array ( [0] => _field_extra_fields_pre_render [1] => field_group_build_pre_render ) [#entity_type] => node [#bundle] => attestat [#groups] => Array ( ) [#fieldgroups] => Array ( ) [#group_children] => Array ( ) [#theme] => node [#node] => stdClass Object ( [vid] => 291 [uid] => 1 [title] => 19714 [log] => Created by FeedsNodeProcessor [status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [nid] => 291 [type] => attestat [language] => und [created] => 1306602719 [changed] => 1306602719 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1306602719 [revision_uid] => 1 [field_att_num] => Array ( [und] => Array ( [0] => Array ( [value] => 017785 [format] => plain_text [safe_value] => 017785 ) ) ) [field_w_id] => Array ( [und] => Array ( [0] => Array ( [value] => 9 [format] => plain_text [safe_value] => 9 ) ) ) [field_zav_id] => Array ( [und] => Array ( [0] => Array ( [value] => 21811 [format] => plain_text [safe_value] => 21811 ) ) ) [field_ex_date] => Array ( [und] => Array ( [0] => Array ( [value] => 2006-06-30T00:00:00 [timezone] => Europe/Helsinki [timezone_db] => Europe/Helsinki [date_type] => date ) ) ) [field_cand_id] => Array ( [und] => Array ( [0] => Array ( [value] => 17089 [format] => plain_text [safe_value] => 17089 ) ) ) [field_att_true] => Array ( [und] => Array ( [0] => Array ( [value] => 0 [format] => plain_text [safe_value] => 0 ) ) ) [field_w_iindex] => Array ( [und] => Array ( [0] => Array ( [value] => СТ [format] => plain_text [safe_value] => СТ ) ) ) [field_w_service] => Array ( [und] => Array ( [0] => Array ( [value] => мастера [summary] => [format] => plain_text [safe_value] =>
мастера
[safe_summary] => ) ) ) [field_cand_famely] => Array ( [und] => Array ( [0] => Array ( [value] => ФИЛ [format] => plain_text [safe_value] => ФИЛ ) ) ) [field_cand_name] => Array ( [und] => Array ( [0] => Array ( [value] => Анатолий [format] => plain_text [safe_value] => Анатолий ) ) ) [field_cand_oldname] => Array ( [und] => Array ( [0] => Array ( [value] => Анатольевич [format] => plain_text [safe_value] => Анатольевич ) ) ) [field_att_note] => Array ( [und] => Array ( [0] => Array ( [value] => [format] => plain_text [safe_value] => ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1306602719 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [print_display] => 0 [print_display_comment] => 0 [print_display_urllist] => 0 [name] => admin [picture] => 0 [data] => [print_mail_display] => 0 [print_mail_display_comment] => 0 [print_mail_display_urllist] => 0 [uri] => Array ( [path] => node/291 [options] => Array ( [entity_type] => node [entity] => stdClass Object *RECURSION* ) ) [entity_view_prepared] => 1 ) [#view_mode] => full [#language] => 0-ru [#weight] => 0 [#attached] => Array (
мастера, прораба
специализация: общестроительные работы
[safe_summary] => ) ) ) [field_cand_famely] => Array ( [und] => Array ( [0] => Array ( [value] => ФИЛ [format] => plain_text [safe_value] => ФИЛ ) ) ) [field_cand_name] => Array ( [und] => Array ( [0] => Array ( [value] => Анатолий [format] => plain_text [safe_value] => Анатолий ) ) ) [field_cand_oldname] => Array ( [und] => Array ( [0] => Array ( [value] => Анатольевич [format] => plain_text [safe_value] => Анатольевич ) ) ) [field_att_note] => Array ( [und] => Array ( [0] => Array ( [value] => [format] => plain_text [safe_value] => ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1306602719 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [print_display] => 0 [print_display_comment] => 0 [print_display_urllist] => 0 [name] => admin [picture] => 0 [data] => [print_mail_display] => 0 [print_mail_display_comment] => 0 [print_mail_display_urllist] => 0 [uri] => Array ( [path] => node/291 [options] => Array ( [entity_type] => node [entity] => stdClass Object *RECURSION* ) ) [entity_view_prepared] => 1 ) [date] => 28.05.2011, 20:11 [node_url] => /att/19714 [page] => 1 [content] => Array ( [print_links] => Array ( [#prefix] => [#markup] => [#suffix] => [#weight] => -101 ) [comments] => Array ( ) [links] => Array ( [#theme] => links__node [#pre_render] => Array ( [0] => drupal_pre_render_links ) [#attributes] => Array ( [class] => Array ( [0] => links [1] => inline ) ) [node] => Array ( [#theme] => links__node__node [#links] => Array ( ) [#attributes] => Array ( [class] => Array ( [0] => links [1] => inline ) ) ) [comment] => Array ( [#theme] => links__node__comment [#links] => Array ( ) [#attributes] => Array ( [class] => Array ( [0] => links [1] => inline ) ) ) [nodereference_url] => Array ( [#theme] => links__node__nodereference [#links] => Array ( ) [#attributes] => Array ( [class] => Array ( [0] => links [1] => inline ) ) ) ) ) [display_submitted] => [submitted] => [user_picture] => [rdf_template_variable_attributes_array] => Array ( [date] => Array ( [property] => Array ( [0] => dc:date [1] => dc:created ) [content] => 2011-05-28T20:11:59+03:00 [datatype] => xsd:dateTime ) [name] => Array ( [rel] => Array ( [0] => sioc:has_creator ) ) ) [datetime] => 2011-05-28T20:11:59+03:00 [unpublished] => [classes] => article article-type-attestat [attributes] => about="/att/19714" typeof="sioc:Item foaf:Document" [title_attributes] => property="dc:title" datatype="" class="article-title" [content_attributes] => class="article-content" )
хы. а по ссылке пройти никак?
С этой страницы http://www.php.net/manual/ru/datetime.modify.php все считает во всез примерах, пока не подставишь вместо даты $output
Выдает ошибки:
Warning: date_timezone_set() expects parameter 1 to be DateTime, boolean given in format_date() (line 1906 of D:\www\new.by\includes\common.inc).
Warning: date_format() expects parameter 1 to be DateTime, boolean given in format_date() (line 1916 of D:\www\new.by\includes\common.inc).
Warning: date_modify() expects parameter 1 to be DateTime, boolean given in include() (line 40 of D:\www\new.by\sites\all\themes\adaptivetheme\adaptivetheme_bsc\views-view-field--att--field-ex-date.tpl.php).
Warning: date_format() expects parameter 1 to be DateTime, boolean given in include() (line 41 of D:\www\new.by\sites\all\themes\adaptivetheme\adaptivetheme_bsc\views-view-field--att--field-ex-date.tpl.php).
$date = date_create('12.12.2006');
date_modify($date, '+3 year');
echo date_format($date, 'd.m.Y');
?>
12.12.2009
$date = date_create($output);
date_modify($date, '+3 year');
echo date_format($date, 'd.m.Y');
?>
Warning: date_modify() expects parameter 1 to be DateTime, boolean given in include() (line 28 of D:\www\new.by\sites\all\themes\adaptivetheme\adaptivetheme_bsc\views-view-field--att--field-ex-date.tpl.php).
Warning: date_format() expects parameter 1 to be DateTime, boolean given in include() (line 29 of D:\www\new.by\sites\all\themes\adaptivetheme\adaptivetheme_bsc\views-view-field--att--field-ex-date.tpl.php).
Больше никаких идей нет?
Petro, Вы решили свою проблему? Если решили напишите, пожалуйста, как.
не, так и не решил
Может кто-нибудь подскажет как в Drupal 7 получить значение поля 'Дата' созданного модулем Date и преобразовать это значение в другой вид, например: Y|n|j