跳到主要内容

如何在Excel中将数字转换为年/月/日或日期?

作者:凯莉 最后修改时间:2020-04-22

我们可以轻松地在Excel中计算两个日期之间的天数,但是如何将天数显示为年/月/日,例如“1年4个月25天“?如果将数字yyyymmdd转换为正常日期该怎么办?本文讨论的是将数字转换为年/月/日或Excel中的日期。


将数字(天)转换为年/月/日

此方法将引入一个公式,将天数转换为年/月/日,例如“1年4个月25天在Excel中。”,请执行以下操作:

1。 选择一个空白单元格,您将输出转换结果,并在其中输入以下公式,然后按 输入 键。

= DATEDIF(0,A2,“ y”)&“年”&DATEDIF(0,A2,“ ym”)&“月”&DATEDIF(0,A2,“ md”)&“天”

注意:A2是您要转换为年/月/日的天数的单元格。

2。 继续选择转换结果的单元格,然后根据需要将其“填充手柄”拖动到该范围。 然后,您将看到所有数字都转换为年/月/日。 看截图:

只需单击一下即可删除所有公式,但保留多个单元格中的计算值


Kutools for Excel - 使用 300 多种基本工具增强 Excel 功能。 享受全功能 30 天免费试用,无需信用卡! 立即行动吧!

使用出色的工具将数字(天)转换为年/月/日

有些用户可能觉得很难记住 Excel 中将天数转换为年/月/日的公式。在这里我推荐 Kutools for Excel 的公式助手来快速完成对话,而无需记住痛苦的公式。

Kutools for Excel - 包含 300 多个 Excel 基本工具。 享受全功能 30 天免费试用,无需信用卡! 现在下载!

1。 选择您要将计算结果放在的单元格,然后单击 库工具 > 公式助手 > 公式助手 启用该功能。

2。 在“公式帮助器”对话框中,请选择 日期 来自 公式类型 下拉列表,单击以突出显示 将天转换为年月日 ,在 选择一个公式 列表框,然后在 联系电话 框,最后单击 Ok 按钮。

现在,计算结果将输出到所选单元格中。 如有必要,您可以拖动此单元格的“自动填充手柄”以将此公式复制到其他单元格。

将通用数字转换为默认日期格式的日期

有时,您将日期键入或粘贴到Excel中,但日期显示为5位数的通用数字。 在这种情况下,您可以使用以下方法轻松地将5位数的通用数字转换为日期:

选择5位数字,然后单击 主页 > 数字格式 盒子> 短期约会。 然后,您将看到所有选定的5位数字立即转换为具有默认日期格式的日期。


使用自定义日期格式将通用数字转换为日期

Kutools for Excel的 套用日期格式 实用程序可以帮助您使用自定义日期格式将5位数字快速转换为日期。

Kutools for Excel - 包含 300 多个 Excel 基本工具。 享受全功能 30 天免费试用,无需信用卡! 现在下载!

1。 选择5位数的数字,然后单击 库工具 > 格式 > 套用日期格式.

2.在打开的“应用日期格式”对话框中,选择要在 日期格式 框,然后单击 Ok 按钮。 然后,您将看到所有数字都以指定的日期格式转换为日期。 看截图:


一键将数字yyyymmdd转换为日期

有时,您可能会得到一些特殊的yyyymmdd数,例如20151215。本节将向您展示一种简单的方法,只需单击一下即可将 转换为日期 Kutools for Excel 的实用程序。

Kutools for Excel - 包含 300 多个 Excel 基本工具。 享受全功能 30 天免费试用,无需信用卡! 现在下载!

选择具有特殊编号yyyymmdd的单元格,然后单击 库工具 > 内容 > 转换为日期。 看截图:

然后,您将看到所有选定的数字都与正常日期一致。 看截图:

请点击 关闭 按钮关闭“转换为日期”对话框。


演示:在Excel中将数字转换为日期


Kutools for Excel:超过 300 个方便的工具触手可及! 立即开始 30 天免费试用,没有任何功能限制。 立即下载!

相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (24)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
=YIL(B6)-YIL(A6) & " Yıl " & EĞER(AY(B6)>AY(A6);AY(B6)-AY(A6);AY(A6)-AY(B6)) & " Ay " & EĞER(GÜN(B6)>GÜN(A6);GÜN(B6)-GÜN(A6);GÜN(A6)-GÜN(B6)) & " Gün " bu şekil negatif işareti kaldırabilirsiniz:
This comment was minimized by the moderator on the site
Hi i have one doubt could you say please I want to return as 5.6 years in excel how i can write
This comment was minimized by the moderator on the site
I'm used the formula at the beginning of this topic to calculate how long my employees have worked so I can setup quarterly progress reviews with them. I have the number generated from a formula that gives me how many days from hire date until current date. What is the change in the formula to go from Hire date to the brake down of year/month/day?
This comment was minimized by the moderator on the site
In my situation, I wanted years and months if possible; if not, I wanted just months or just days. I ended up with:
=IF(cellcontainingdays="","",IF(DATEDIF(0,cellcontainingdays,"y")=0,"",CONCATENATE(DATEDIF(0,cellcontainingdays,"y")," years")) & IF(DATEDIF(0,cellcontainingdays,"ym")=0,"",IF(AND(DATEDIF(0,cellcontainingdays,"ym")<>0,DATEDIF(0,cellcontainingdays,"y")=0),CONCATENATE(DATEDIF(0,cellcontainingdays,"ym")," months"),CONCATENATE(", ",DATEDIF(0,cellcontainingdays,"ym")," months"))) & IF(DATEDIF(0,cellcontainingdays,"md")=0,"",IF(AND(DATEDIF(0,cellcontainingdays,"md")<>0,DATEDIF(0,cellcontainingdays,"y")=0,DATEDIF(0,cellcontainingdays,"ym")=0),CONCATENATE(DATEDIF(0,cellcontainingdays,"md")," days"),"")))
This comment was minimized by the moderator on the site
=IF(DATEDIF(0;A1;"y")=0;"";DATEDIF(0;A1;"y")&" year(s), ") & IF(DATEDIF(0;A1;"ym")=0;"";DATEDIF(0;A1;"ym")&" month(s), ") & IF(DATEDIF(0;A1;"md")=0;"";DATEDIF(0;A1;"md")&" day(s)")
This comment was minimized by the moderator on the site
How to handle negative numbers?

it gives #NUM! error.
This comment was minimized by the moderator on the site
Hi Ahmed,

what about changing the negative numbers to positive with ABS function, and then adding minus sign before the whole formula?
This comment was minimized by the moderator on the site
I love you guys.
This comment was minimized by the moderator on the site
Is there a way to automatically omit 0 values? For example, if the formula returns "0 years, 7 months, 16 days", is there a way for it to show up as "7 months, 16 days" instead?
This comment was minimized by the moderator on the site
=IFERROR(IF(DATEDIF(0,M2,"y")>0,DATEDIF(0,M2,"y")&" Years ","")&IF(DATEDIF(0,M2,"ym")>0,DATEDIF(0,M2,"ym")&" Months ","")&IF(DATEDIF(0,M2,"md")>0,DATEDIF(0,M2,"md")&" Days",""),"")
This comment was minimized by the moderator on the site
=IF(DATEDIF(0;A1;"y")=0;"";DATEDIF(0;A1;"y")&" year(s), ") & IF(DATEDIF(0;A1;"ym")=0;"";DATEDIF(0;A1;"ym")&" month(s), ") & IF(DATEDIF(0;A1;"md")=0;"";DATEDIF(0;A1;"md")&" day(s)")
This comment was minimized by the moderator on the site
=IFERROR(IF(DATEDIF(0,M2,"y")>0,DATEDIF(0,M2,"y")&" Years ","")&IF(DATEDIF(0,M2,"ym")>0,DATEDIF(0,M2,"ym")&" Months ","")&IF(DATEDIF(0,M2,"md")>0,DATEDIF(0,M2,"md")&" Days",""),"")
This comment was minimized by the moderator on the site
=CONCATENATE(IF(INT(A2/365)>0,CONCATENATE(INT(A2/365)," Years "),""),CONCATEN ATE(IF(INT(MOD( A2,365)/30)>0,C ONCATENATE(INT( MOD(A2,365)/30) ," Months "),""),CONCATEN ATE(IF(MOD(MOD( A2,365),30)>0,C ONCATENATE(MOD( MOD(A2,365),30) ," Days "),""),))) My formula is ok, When you will copy the formula it will contain some space in word CONCATENATE Like C ONCATENATE/CONCATEN ATE. Please correct the word concatenate. Then i think it will work.
This comment was minimized by the moderator on the site
hello, thanks for the feedback but it's still not working, can you please send me your email so i can show you the table am doing ?! maybe some mistake is there. my email is . now my final table will contain number of days, like for example after the calculations the result will be (123) which is number of days so i want to convert it into ( year , month , days ). or if you have a formula to calculate the defferance between two dates and show the results as ( x year , x month , x days ) that would be super. waiting for your feedback and thanks.
This comment was minimized by the moderator on the site
=IF(DATEDIF(A1;A2;"y")=0;"";DATEDIF(A1;A2;"y")&" year(s), ") & IF(DATEDIF(A1;A2;"ym")=0;"";DATEDIF(A1;A2;"ym")&" month(s), ") & IF(DATEDIF(A1;A2;"md")=0;"";DATEDIF(A1;A2;"md")&" day(s)")
This comment was minimized by the moderator on the site
change every ; to ,
This comment was minimized by the moderator on the site
And what table is that ,that you say your doing?
There are no comments posted here yet
Load More
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations