简体   繁体   English

基于日期的星期数

[英]Week number based on Date

I need to make week number based on given date. 我需要根据给定的日期制作星期数。

Today 28-08-18 今天28-08-18
Week ..... 周...

        30-07-18    1
        06-08-18    2
        13-08-18    3
        20-08-18    4
        27-08-18    5
        03-09-18    6
        10-09-18    7
        17-09-18    8
        24-09-18    9
        01-10-18    10
        08-10-18    11
        15-10-18    12
        22-10-18    13
        29-10-18    14

I want the cell next to "week" to be based on today's date. 我希望“周”旁边的单元格基于今天的日期。

  • Start by inserting a date in any cell, that will be the first week. 首先在任何单元格中插入日期,即第一周。
  • Create a function that calculates the difference between its adjacent cell and the first and divides it by 7. Voilà you've got the week number. 创建一个函数来计算其相邻单元格与第一个单元格之间的差异,然后将其除以7。Voilà,您得到了星期数。 You can round it if you want. 您可以根据需要四舍五入。

The formula is as follows: Floor((First date - Current date)/7). 公式如下:下限((第一个日期-当前日期)/ 7)。

Useful link for subtraction: http://www.theexceladdict.com/_t/t040303.htm . 减法的有用链接: http : //www.theexceladdict.com/_t/t040303.htm

Good luck, Alex 祝你好运,Alex

Assuming 30-07-18 is located @ A1. 假设30-07-18位于A1。 in B1, type in : 在B1中,输入:

=WEEKNUM(A1,2)-WEEKNUM($A$1,2)+1

and drag it down. 并将其向下拖动。 Glad that you'd tried. 很高兴您尝试过。 ( : (:

All the best. 祝一切顺利。

Your base date (BD) may not be the start of the week (SOW), so the general solution could be 您的基准日期(BD)可能不是一周的开始(SOW),因此一般的解决方案可能是

  1. calculate the SOW from your base date: SOW = BD - WEEKDAY(BD)+2 根据您的基准日期计算SOWSOW = BD - WEEKDAY(BD)+2
  2. calculate the distance DI from given date (GD) to SOW : DI = GD - SOW 计算给定日期(GD)到SOW的距离DIDI = GD - SOW
  3. convert distance into weeknumber W = INT(DI/7) 将距离转换为周数W = INT(DI / 7)

在此处输入图片说明

EDIT: 编辑:

SOW = IF(WEEKDAY(BD)=1;BD-6;BD-WEEKDAY(BD)+2)

this is to cover cases where BD is a Sunday and SOW should be the Monday before (not after) 这是为了涵盖BD是星期天而SOW应该是星期一之前(而不是之后)的情况

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM