找出一个月中给定日期的周数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了找出一个月中给定日期的周数相关的知识,希望对你有一定的参考价值。

This simple function allows you to find a weeks position in the month based on a given date. For instance I needed to alert the user their date was the "Second Week Of January" during a given month. I may never use it again but it came in very handy for this particular project.
  1. <?php
  2.  
  3. function week_number( $date = 'today' )
  4. {
  5. return ceil( date( 'j', strtotime( $date ) ) / 7 );
  6.  
  7. }
  8.  
  9. ?>
  10.  
  11. Usage Example:
  12.  
  13. <?php
  14.  
  15. $week_num = week_number();
  16.  
  17. $month = date("J", time());
  18.  
  19. echo "Today is the $week_num week of $month";
  20.  
  21. ?>

以上是关于找出一个月中给定日期的周数的主要内容,如果未能解决你的问题,请参考以下文章

亚马逊 - Redshift:给定日期的周数错误

如何在 Power Query M 中按给定日期查找 4 周滚动周期的周数

如何计算编号。从当前周到给定周的周数?

PHP - 计算两个日期之间的周数

怎么取两个日期之间的周数

JS将日期转换成当年的周数(work week)