从日期获取周数和日期

时间:2017-07-11 10:22:30

标签: php

输入:17-07-2017
输出 - >>第3个星期一

提前致谢
这是我的代码:

$datee = "2017-07-17";
$timestamp = strtotime($datee);
$day = date('l', $timestamp);
$week = date('w', $timestamp);
echo $day;
echo $week;

3 个答案:

答案 0 :(得分:1)

Action()
{

    web_custom_request("Calculate",
       "URL=http://sdfsdfsdfgsdfgsdfgsdfgsdfgsd/sdfgsdf/sdfgsd",
       "Method=POST",
       "Resource=0",
       "EncType=application/json",
       "Mode=HTTP", 
       "Body={\"program\":\"L002\",\"Number\":null,\"serviceNumber\":\"09000\",\"customerStateName\":\"{state}\",\"storeCode\":\"{store}\",\"Amount\":\"{amount}\",\"paymentDetails\":[{\"type\":\"{types}\",\"amount\":{amount}\"}]}",LAST);


    return 0;
}

您可以修改https://3v4l.org/dg5Xa

处的代码

答案 1 :(得分:0)

非常简单的答案已经存在

In PHP, how to know how many mondays have passed in this month uptil today?

$now=time();
if (($dow = date('w', $now)) == 0) $dow = 7; 
$begin = $now - (86400 * ($dow-1));

echo "Monday: ".ceil(date('d', $begin) / 7)."<br/>";

答案 2 :(得分:-1)

'w'格式是当天的数字表示(0表示星期日,6表示星期六)。它不代表该月的一周。要获得该月的一周,您可以使用以下功能

 function week_number( $date = 'today' ) {   
        return ceil( date( 'j', strtotime( $date ) ) / 7 ); 
    } 

所以你的代码应该是:

  $datee = "2017-07-17";
  $timestamp = strtotime($datee);
  $day = date('l', $timestamp);
  $week = week_number($datee);
  echo $day;
  echo $week;

参考:Get week number in month from date in PHP?