CCK 날짜 필드를 사용했습니다. 마트의 끝에서 strtotime (> = 3 월 29 일)은 strtotime ('1 개월')에 대한 잘못된 결과를 반환합니다.strtotime이 '-1 개월'에 대한 잘못된 타임 스탬프를 반환합니다.
// Current date Mar 30
$time = strtotime('-1 month');
print date('m/d/Y', $time);
아이디어가 있으십니까?
CCK 날짜 필드를 사용했습니다. 마트의 끝에서 strtotime (> = 3 월 29 일)은 strtotime ('1 개월')에 대한 잘못된 결과를 반환합니다.strtotime이 '-1 개월'에 대한 잘못된 타임 스탬프를 반환합니다.
// Current date Mar 30
$time = strtotime('-1 month');
print date('m/d/Y', $time);
아이디어가 있으십니까?
이 카운터 직관적이지만 : 내가 아는 방법은 relative date/time formats of PHP 사용 "마지막/다음 달 같은 날"얻을 할 수 있습니다
03/31/2011 + 1 month = 04/31/2011 => 05/01/2011
: 같은 이유로
03/30/2011 - 1 month = 02/30/2011 => 03/02/2011
.
'이전 달'도 잘못된 결과를 반환합니다. CCK 날짜 필드에 기본값을 설정할 수있는 방법이 없습니다 (Google은 조용합니다.) – dobeerman
내 솔루션
/*
* Implementation of hook_form_alter().
*/
function report_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case AUTO_REPORT_NODE_FORM:
// Fix bug with strtotime('-1 month')
$currentYear = date('Y');
$currentMonth = date('n');
if($currentMonth == 1){
$relevantMonth = 12;
$relevantYear = $currentYear -1;
}
else{
$relevantMonth = $currentMonth - 1;
$relevantYear = $currentYear;
}
$form['field_datestamp'][0]['#default_value']['value'] = date("Y-m-d h:m:s", strtotime($relevantYear .'-'. $relevantMonth));
break;
}
}
나는 드루팔에 익숙한 아니에요하지만 당신은 같은 것을 사용할 수 있습니다 : 그것은의 총 수를 초과하는 경우 지난달 당신에게 일을주고
min(date('t'), date('d')); // would yield 28 on March 30th
및 일, 2 월 30 일 예 그것은 min 함수 min (28)을 사용하여 다시 되돌아갑니다.
이것은 Drupal 문제가 아니며 모든 PHP와 관련이 있습니다. –
date() 함수를 사용하는 것이 Drupal에 특화된 것은 아니지만, Drupal에서 대부분의 용도에 대해 format_date() 함수를 사용해야한다는 점에 유의해야합니다 (http://api.drupal.org/api/drupal /includes--common.inc/function/format_date)를 사용하여 시간대 및 기타 Drupal 관련 구성을 고려합니다. – jhedstrom
CCK 날짜 필드를 사용했습니다. – dobeerman