简体   繁体   English

在Excel中将月份编号从完整日期单元格转换为文本月份

[英]Converting month number from full date cell into text month in Excel

So I have a pretty long column with name dates and hours, like this: 14/01/2017 03:30 所以我有一长列列出了日期和时间,例如:14/01/2017 03:30
(They are DD/MM/YYYY HH:MM) (它们是DD / MM / YYYY HH:MM)

I need to get the month number and show it as text, like January, February, and so on. 我需要获取月份号并将其显示为文本,例如一月,二月等。 If I format the destination cell as 'MMM' all the column cells show January even if the given month is 2, 3, or let's say 12. I also tried the formula =TEXT(L2,"mmmm") (since the given info come from column F. 如果我将目标单元格的格式设置为“ MMM”,即使给定的月份是2、3或12,所有列单元格都显示1月。我也尝试了公式= TEXT(L2,“ mmmm”)(因为给定的信息来自F列。

Any ideas? 有任何想法吗?

sounds like your date and time are stored as text and not in excels serial date format. 听起来像您的日期和时间存储为文本,而不是Excel的序列日期格式。 You can test this by changing the format of the cell to general and seeing if anything happens if nothing changes then its text. 您可以通过将单元格的格式更改为“常规”并进行测试,看看如果什么都没有改变,那么文本是否会发生任何变化。 another way would be to use the formula =istext(A1) where A1 is a cell with a date in it. 另一种方法是使用公式=istext(A1) ,其中A1是其中有日期的单元格。

Now ASSUMING you do have dates in text format, I would suggest converting them to excels date serial. 现在假设您确实有文本格式的日期,我建议将其转换为Excel日期序列。 There are numerous ways of doing this. 有很多方法可以做到这一点。 I will show you one way. 我将向您展示一种方式。

This will strip each component of the text out and then recombine it. 这将删除文本的每个组成部分,然后重新组合。 We will assume your date in is A1 我们假设您的约会日期为A1

Strip out the year 剔除年份

=MID(A1,7,4)

Strip out the month 剔除月份

=MID(A1,4,2)

Strip out the day 去除一天

=LEFT(A1,2)

Now to recombine it: 现在重新组合一下:

=DATE(MID(A1,7,4),MID(A1,4,2),LEFT(A1,2))

That will give you the date in an integer format that excel can then turn around and display as needed. 这将为您提供整数格式的日期,然后excel可以将其转回并根据需要显示。

In order not to lose the time component you should strip that part off as well and combine it with the date. 为了不丢失时间部分,您还应该剥离该部分并将其与日期结合在一起。 Remember the date is an integer, and the time is everything after the decimal. 请记住,日期是整数,时间是小数点后的所有内容。 Think of time as a fraction of a day. 将时间视为一天的一小部分。

To get time out use: 要超时,请使用:

=RIGHT(A1,5)

and to convert it to excel time: 并将其转换为excel时间:

=TIMEVALUE(RIGHT(A1,5))

and to get the two together, simply add: 并将两者结合在一起,只需添加:

=DATE(MID(A1,7,4),MID(A1,4,2),LEFT(A1,2)+TIMEVALUE(RIGHT(A1,5))

The key part to this whole thing is you will need to format that cell to display what you want. 整个过程的关键部分是您需要格式化该单元格以显示所需的内容。 you can either choose a preformatted style from the drop down menu, or you can apply custom formatting. 您可以从下拉菜单中选择一种预格式化的样式,也可以应用自定义格式。 Setting the custom format to MMMM should display just the full name of the month. 将自定义格式设置为MMMM应该仅显示月份的全名。

IF you actually need the text of the month and not just the format, then you could use the formula from your question: 如果您实际上需要的是月份文本,而不仅是格式,那么您可以使用问题中的公式:

=TEXT(<insert appropriate formula from above>,"mmmm")

尝试使用MID仅获取月份,然后获取TEXT()

=TEXT(MID(A1,SEARCH("/",A1)+1,2),"MMMM")

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

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