2012年1月15日 星期日

日曆的上個月、下個月

寫了一個日曆,
取得目前月份的上個月或下個月,
主要是使用strtotime(),來作目前月份的加減。
http://php.net/manual/en/function.strtotime.php

$YM = isset($_POST['YM']) ? $_POST['YM'] : date('Y-m');
$YMD = "$YM-01";
switch($_POST['type']){
  default:
  case 'curr'://目前月份
  break;
  case 'next'://下個月
    $YM = date("Y-m", strtotime('+1 month',strtotime($YMD)));
  break;
  case 'prev'://上個月
    $YM = date("Y-m", strtotime('-1 month',strtotime($YMD)));
  break; 
}

沒有留言:

張貼留言