这是如何在Excel中使用函数计算日期的方法。

huangapple go评论61阅读模式
英文:

this is how to calculate dates in excel using functions

问题

2017 年,伊斯兰斋月拉马丹于周五,5月26日开始。这占一年的多少分数?我手动计算为 146/365,但我正在寻找一个Excel公式来计算它。

英文:

In 2017 the Islamic month of fasting, Ramadan, began on Friday, 26 May. What fraction of the year was this? I calculated it manually as 146/365, but I am looking for an excel formula to calculate it.

答案1

得分: 2

If you have the date when Ramadan began on Cell A1, then:

=A1 - DATE(YEAR(A1),1,0)

or

=A1 - DATE(YEAR(A1),1,1)+1

will give you the Ramadan day of the year, to get the fraction:

=(A1 - DATE(YEAR(A1),1,0))/(DATE(YEAR(A1),12,31) - DATE(YEAR(A1),1,1)+1)

or using LET to avoid repetition:

=LET(r, A1, y, YEAR(r), (r-DATE(y,1,0))/(DATE(y,12,31) - DATE(y,1,1)+1))

You can replace the denominator using a leap year condition as follows:

=LET(r, A1, y, YEAR(A1), (r-DATE(y,1,0))/(365+IF(MONTH(DATE(y,2,29))=2,1,0)))
英文:

If you have the date when Ramadan began on Cell A1, then:

=A1 - DATE(YEAR(A1),1,0)

or

=A1 - DATE(YEAR(A1),1,1)+1

will give you the Ramadan day of the year, to get the fraction:

=(A1 - DATE(YEAR(A1),1,0))/(DATE(YEAR(A1),12,31) - DATE(YEAR(A1),1,1)+1)

or using LET to avoid repetition:

=LET(r, A1, y, YEAR(r), (r-DATE(y,1,0))/(DATE(y,12,31) - DATE(y,1,1)+1))

You can replace the denominator using a leap year condition as follows:

=LET(r, A1, y, YEAR(A1), (r-DATE(y,1,0))/(365+IF(MONTH(DATE(y,2,29))=2,1,0)))

答案2

得分: 0

=YEARFRAC(start_date,end_date)

其中,你的 start_date:1/1/2017,和你的 end_date:5/26/2017

英文:

You can use:

=YEARFRAC(start_date,end_date)

whereby, your start_date: 1/1/2017, and your end_date: 5/26/2017

huangapple
  • 本文由 发表于 2023年2月7日 00:56:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364324.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定