如何获得一个时间段内有几天是周末的?

xiaopar 2006-06-25 01:57:39
我现在做的一个网站里计算价格的时候有个关于周末价,跟普通时间价格不一样
当客户选择一个时间段,我怎么判断他选的时间里有几天是周六和周日的呢

比如6月23号到28号,中间的有两天 24号和25号是周末,按周末价$lastprice
其他时间是一般价格$price

我怎么把计算给出的时间段内有几天是周日和周六呢

....................
...全文
293 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lantersen 2006-06-26
  • 打赏
  • 举报
回复
$cotainer = array();
$days = array("20060622","20060624","20060625");
foreach($days as $dayvalue)
{
$dayvalue = strtotime($dayvalue);
$day = date("D", $dayvalue);
if ( $day == "Sun" || $day == "Sat" )
{
array_push($cotainer, $dayvalue);
}
unset($day);
}
print_r($cotainer);
xiaopar 2006-06-26
  • 打赏
  • 举报
回复
搞定了,原来我的代码里前面一个变量多了个',这里这样写是没错的,呵呵
谢谢大家
xiaopar 2006-06-26
  • 打赏
  • 举报
回复
zeroleonhart(没有螺母的螺丝钉) 大哥
能不能详细点啊,不懂怎么做啊,谢谢了
zeroleonhart 2006-06-25
  • 打赏
  • 举报
回复
use a variable to store the number of the days,do not use the array
xiaopar 2006-06-25
  • 打赏
  • 举报
回复
我用错了,用成date("w","2006-06-23");这样子了,所以出错,呵呵

可是这只是判断某一天是星期几啊,还是没办法判断时间段中有几天是周末

我的程序:
$str1=strtotime($str_time);
$str2=strtotime($of_time);

$daycount=($str2-$str1)/(3600*24);

for($i=1;$i<$daycount;$i++){
$every_day=date("Y-M-d",$str1+3600*24*$i);
if(date("w",strtotime($every_day)=='0' or date("w",strtotime($every_day)=='6')
$lasts="last[]";
}
$last_num=count($lasts);


这样写出错,帮我改改吧
kakapowu 2006-06-25
  • 打赏
  • 举报
回复
date("w",strtotime("2006-06-23"));

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧