我有一个数据,其中包含酒店入住日期和退房日期。我会计算在酒店度过的天数,我只想减去它们,我就有天差。
我现在必须接收住了超过31天的客户,并了解他们每月花了多少天。例如,有些人在2015年7月18日登记并于2015年9月18日退房,应该有多个栏目,对应于该栏目,每月花费的天数为13 31 18。 (7月,8月,9月)
示例数据和示例输出:
Client Check In Check Out
Majestica Inn 22-May-15 22-Jun-15 31 9 22
Twin Tree 29-May-15 30-Jun-15 32 2 31
Connaught Mews 1-Jun-15 31-Jul-15 60 29 31
Majestica Inn 18-Jul-15 18-Sep-15 62 13 31 18
Majestica Inn 18-Jul-15 18-Sep-15 62 13 31 18
我是Excel的新手,请帮助。
答案 0 :(得分:0)
如果您可以灵活地了解列数,那么您可以使用以下公式来获得所需的输出。
获得日子的公式:
备注:将此公式粘贴到单元格e2中,然后拖动&复制。
= IFERROR(IF(AND(MONTH(E $ 2及 “ - ” &安培; YEAR($ B3))> = MONTH($ B3),月(E $ 2及 “ - ” &安培; YEAR($ C3))≤; = MONTH($ C3)),IF(MONTH(E $ 2及 “ - ” &安培; YEAR($ B3))= MONTH($ B3),DATEDIF($ B3,EOMONTH($ B3,0 ), “d”),IF(MONTH(E $ 2及 “ - ” &安培; YEAR($ B3))= MONTH($ C3),DATEDIF(DATE(YEAR($ C3),月($ C3),1 ),$ C3, “d”)+ 1,DATEDIF(DATE(YEAR($ C3),月(E $ 2及 “ - ” &安培; YEAR($ B3)),1),EOMONTH(DATE(YEAR($ C3),月(E $ 2及 “ - ” &安培; YEAR($ B3)),1),0), “d”)+ 1)), “”), “ERR”)
连接公式:
= IFERROR(DATEDIF($ B2,$ C2, “d”)及IF(E2<> “中”, “”, “”)及CONCATENATE(E2,IF(F2<> “中” , “”, “”),F2,IF(G2<> “中”, “”, “”),G2,IF(H2<> “中”, “”, “”),H 2,IF (I2<> “中”, “”, “”),I 2,IF(J2<> “中”, “”, “”),J2,IF(K2<> “中”, “”, “”),K2,IF(L2<> “中”, “”, “”),L2,IF(M2<> “中”, “”, “”),M2,IF(N2<> “”, “”, “”),N 2,IF(O2<> “中”, “”, “”),O 2,IF(P2<> “中”, “”, “”),P2 ),“”)
答案 1 :(得分:0)
如果您不想添加任何列,请尝试这一个......
粘贴在Cell D2 ......
= IFERROR(SUBSTITUTE(DATEDIF($ B2,$ C2," d")&安培;""&安培; IFERROR(IF(AND(MONTH("扬"&安培;" - "&安培; YEAR($ B2))> = MONTH($ B2),月("扬"&安培;" - & #34;&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(MONTH("扬"&安培;" - "&安培; YEAR($ B2 ))= MONTH($ B2),DATEDIF($ B2,EOMONTH($ B2,0)" d&#34),IF(MONTH("扬"&安培;" - "&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE(YEAR($ C2),月($ C2),1),$ C2," d" )+ 1,DATEDIF(DATE(YEAR($ C2),月("扬"&安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE (YEAR($ C2),月("扬"&安培;" - "&安培; YEAR($ B2)),1),0)," d&#34 ;)+ 1))及;""""),"错误")及IFERROR(IF(AND(MONTH(&#34 ;二月"&安培;" - "&安培; YEAR($ B2))> = MONTH($ B2),月("二月"&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(MONTH("二月"&安培;" - "&安培; YEAR($ B2))= MONTH($ B2),DATEDIF($ B2,EOMONTH($ B2,0)" d&#34),IF(MONTH("二月"&安培;&#34 ; - "&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE(YE AR($ C2),月($ C2),1),$ C2," d&#34)+ 1,DATEDIF(DATE(YEAR($ C2),月("二月" &安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2),月("二月"&安培;" - "&安培; YEAR($ B2)),1),0)," d&#34)+ 1))及;"""&# 34)"错误")及IFERROR(IF(AND(MONTH("三月"&安培;" - "&安培; YEAR($ B2)) > = MONTH($ B2),月("三月"&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(个月("三月"&安培;" - "&安培; YEAR($ B2))= MONTH($ B2),DATEDIF($ B2,EOMONTH($ B2,0),& #34; d&#34),IF(MONTH("三月"&安培;" - "&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE (YEAR($ C2),月($ C2),1),$ C2," d&#34)+ 1,DATEDIF(DATE(YEAR($ C2),月("三月&#34 ;&安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2),月("三月"&安培;" - "&安培; YEAR($ B2)),1),0)," d&#34)+ 1))及;"""& #34;),"错误")及IFERROR(IF(AND(MONTH("四月"&安培;" - "&安培; YEAR($ B2) )> = MONTH($ B2),月("四月"&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(MONTH("四月"&安培;" - "&安培; YEAR($ B2))= MONTH($ B2),DATEDIF($ B2,EOMONTH($ B2,0)" d&#34),IF(MONTH("四月"&安培;" - "&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE(YEAR($ C2),月($ C2),1),$ C2," d&#34)+ 1,DATEDIF(DATE(YEAR($ C2),月(& #34;四月"&安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2),月("四月" &安培;" - "&安培; YEAR($ B2)),1),0)," d&#34)+ 1))及;"" ""),"错误")及IFERROR(IF(AND(MONTH("五月"&安培;" - "&安培; YEAR($ B2))> = MONTH($ B2),月("五月"&安培;" - "&安培; YEAR($ C2))≤= MONTH( $ C2)),IF(MONTH("五月"&安培;" - "&安培; YEAR($ B2))= MONTH($ B2),DATEDIF($ B2,EOMONTH( $ B2,0)" d&#34),IF(MONTH("五月"&安培;" - "&安培; YEAR($ B2))= MONTH( $ C2),DATEDIF(DATE(YEAR($ C2),月($ C2),1),$ C2," d&#34)+ 1,DATEDIF(DATE(YEAR($ C2),月( "五月"&安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2),月("五月&#34 ;&安培;" - "&安培; YEAR($ B2)),1),0)," d&#34)+ 1))&安培;""""),"错误")及IFERROR(IF(AND(MONTH("君"&安培;" - "&安培; YEAR($ B2))> = MONTH($ B2),月("君"&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(MONTH("君"&安培;" - "&安培; YEAR($ B2))= MONTH( $ B2),DATEDIF($ B2,EOMONTH($ B2,0)" d&#34),IF(MONTH("君"&安培;" - " &安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE(YEAR($ C2),月($ C2),1),$ C2," d&#34)+ 1,DATEDIF (DATE(YEAR($ C2),月("君"&安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2 ),月("君"&安培;" - "&安培; YEAR($ B2)),1),0)," d&#34)+ 1) )及;""""),"错误")及IFERROR(IF(AND(MONTH("七月" &安培;" - "&安培; YEAR($ B2))> = MONTH($ B2),月("七月"&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(MONTH("七月"&安培;" - "&安培; YEAR($ B2))= MONTH ($ B2),DATEDIF($ B2,EOMONTH($ B2,0)" d&#34),IF(MONTH("七月"&安培;" - &#34 ;&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE(YEAR($ C2),月($ C2),1),$ C2 " d&#34)+ 1,DATEDIF(DATE(YEAR($ C2),月("七月"&安培;" - "&安培; YEAR($ B2 )),1),EOMONTH(DATE(YEAR($ C2),月("七月"&安培;" - "&安培; YEAR($ B2)),1),0 )" d&#34)+ 1))及;""""),"错误")及IFERROR( IF(AND(MONTH("八月"&安培;" - "&安培; YEAR($ B2))> = MONTH($ B2),月("八月&# 34;&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(MONTH("八月"&安培;" - "&安培; YEAR($ B2))= MONTH($ B2),DATEDIF($ B2,EOMONTH($ B2,0)" d&#34),IF(MONTH("八月"&安培;" - "&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE(YEAR($ C2),月($ C2),1),$ C2," d&#34)+ 1,DATEDIF(DATE(YEAR($ C2),月("八月"&安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2),月("八月"&安培;" - "&安培; YEAR($ B2)),1), 0)," d&#34)+ 1))及;""""),"错误")及IFERROR (IF(AND(MONTH("九月"&安培;" - "&安培; YEAR($ B2))> = MONTH($ B2),月("九月& #34;&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(MONTH("九月&#3 4;&安培;" - "&安培; YEAR($ B2))= MONTH($ B2),DATEDIF($ B2,EOMONTH($ B2,0)" d&#34) ,IF(MONTH("九月"&安培;" - "&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE(YEAR($ C2),月($ C2),1),$ C2," d&#34)+ 1,DATEDIF(DATE(YEAR($ C2),月("九月"&安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2),月("九月"&安培;" - "&安培; YEAR ($ B2)),1),0)," d&#34)+ 1))及;""""),&#34 ;错误")及IFERROR(IF(AND(MONTH("十月"&安培;" - "&安培; YEAR($ B2))> = MONTH($ B2 ),月("十月"&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(MONTH("十月& #34;&安培;" - "&安培; YEAR($ B2))= MONTH($ B2),DATEDIF($ B2,EOMONTH($ B2,0)" d" ),IF(MONTH("十月"&安培;" - "&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE(YEAR($ C2),个月($ C2),1),$ C2," d&#34)+ 1,DATEDIF(DATE(YEAR($ C2),月("十月"&安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2),月("十月"&安培;" - "&安培; YEAR($ B2)),1),0)," d&#34)+ 1))及;"""&#34 ;),"错误")及IFERROR(IF(AND(MONTH("十一月"&安培;" - "&安培; YEAR($ B2))&GT = MONTH($ B2),月("十一月"&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(月("十一月"&安培;" - "&安培; YEAR($ B2))= MONTH($ B2),DATEDIF($ B2,EOMONTH($ B2,0)&# 34; d&#34),IF(MONTH("十一月"&安培;" - "&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE( YEAR($ C2),月($ C2),1),$ C2," d&#34)+ 1,DATEDIF(DATE(YEAR($ C2),月("十一月" &安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2),月("十一月"&安培;" - "&安培; YEAR($ B2)),1),0)," d&#34)+ 1))及;"""&# 34)"错误")及IFERROR(IF(AND(MONTH("减速"&安培;" - "&安培; YEAR($ B2)) > = MONTH($ B2),月("减速"&安培;" - "&安培; YEAR($ C2))≤; = MONTH($ C2)),IF(个月("减速"&安培;" - "&安培; YEAR($ B2))= MONTH($ B2),DATEDIF($ B2,EOMONTH($ B2,0),& #34; d&#34),IF(MONTH("减速"&安培;" - "&安培; YEAR($ B2))= MONTH($ C2),DATEDIF(DATE (YEAR($ C2),月($ C2),1),$ C2," d&#34)+ 1,DATEDIF(d ATE(YEAR($ C2),月("减速"&安培;" - "&安培; YEAR($ B2)),1),EOMONTH(DATE(YEAR($ C2) ,MONTH("减速"&安培;" - "&安培; YEAR($ B2)),1),0)," d&#34)+ 1)) &安培;""""),"错误")&安培;" 0 |"",0 |"""),"&#34)
祝你好运.............