当前位置:首页>开发>正文

php上个月最后一天 php本月的最后一天怎么取

2023-04-11 00:52:37 互联网 未知 开发

php上个月最后一天 php本月的最后一天怎么取

php本月的最后一天怎么取


function get_cmonth_lastday()
{
$date=date("Y-m",time())
$date_arr=explode(-,$date)
$year=$date_arr[0]
$month=$date_arr[1]
$days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

if ($month < 1 OR $month > 12)
{
return 0
}

// Is the year a leap year?
if ($month == 2)
{
if ($year@0 == 0 OR ($year%4 == 0 AND $year0 != 0))
{
return $year.-.$month.-29
}
}

return $year.-.$month.-.$days_in_month[$month - 1]
}
echo get_cmonth_lastday()
?>

php如何得到一个月的最后一天

$firstday date(Y-m-d, mktime(0, 0, 0, date(m), 1))
$lastday date(Y-m-d, mktime(0, 0, 0,date(m) 1,1)-1)

php获取当年的每个月的第一天和最后一天时间戳的函数

/**
* 获取指定月份的第一天开始和最后一天结束的时间戳
*
* @param int $y 年份 $m 月份
* @return array(本月开始时间,本月结束时间)
*/
function mFristAndLast($y="",$m=""){
if($y=="") $y=date("Y")
if($m=="") $m=date("m")
$m=sprintf("d",intval($m))
$y=str_pad(intval($y),4,"0",STR_PAD_RIGHT)
$m>12||$m<1?$m=1:$m=$m
$firstday=strtotime($y.$m."01000000")
$firstdaystr=date("Y-m-01",$firstday)
$lastday = strtotime(date(Y-m-d 23:59:59, strtotime("$firstdaystr 1 month -1 day")))
return array("firstday"=>$firstday,"lastday"=>$lastday)
}

php求当前季度的第一天和最后一天

$date = getdate()
$month = $date[mon] //当前第几个月
$year = $date[year] //但前的年份

$strart = floor($month/3) * 3 //单季第一个月
$strart = mktime(0,0,0,$start,1,$year) //当季第一天的时间戳

$end = mktime(0,0,0,$start 3,1,$year) //当季最后一天的时间戳

请教各位大神,如何在脚本中获取上个月最后一天日期

编写脚本getdate.sh:

[plain] view plain copy
#! /bin/sh
nowdate=`date %Y%m01` #本月第一天
startdate=`date -d"$nowdate last month" %Y%m%d` #上个月第一天
enddate=`date -d"$nowdate last day" %Y%m%d` #上个月最后一天
#遍历上个月的每一天
while (( $startdate <= $enddate ))
do
echo $startdate
startdate=`date -d " 1 day $startdate" %Y%m%d`

最新文章

随便看看