英文:
Create a Combined Excel Column Given Month and Year
问题
如果我已经有了一个年份(例如1980)和一个月份(一月),我该如何在Excel中创建一个新的列来显示合并的日期,比如Jan-80?
由于这个示例没有提供一个具体的日期,所以日期函数无法使用。
尝试了日期函数,但由于需要一个具体的日期值,所以它无法工作。
英文:
If I've been given a year (ex 1980) and a month (January) - how could I create a new column in excel to show a combined date - such as Jan-80?
The date function doesn't work since it requires a day and one has not been provided for this example.
Tried the date function and it did not work given requirement for a day value.
答案1
得分: 2
=TEXT(DATE(A1, MONTH(DATEVALUE(B1 & " 1")), 1), "mmm-yy")
DATE函数将年份、月份号码和固定的日期(1)组合在一起。然后,TEXT函数将日期格式更改为"mmm-yy"。在这里,"mmm"表示短月份名称,"yy"表示两位数年份。
英文:
try this
=TEXT(DATE(A1, MONTH(DATEVALUE(B1 & " 1")), 1), "mmm-yy")
The DATE function puts together the year, month number, and a set day (1). Then, the TEXT function changes the date format to "mmm-yy". Here, "mmm" means the short month name, and "yy" means the two-number year.
答案2
得分: 1
你可以利用Excel将字符串转换为日期的方式,基于你的本地/时间设置。假设你的月份在单元格 A1
中,年份在单元格 B1
中:
=0+("1-"&A1&"-"&B1)
注意:后来我发现破折号分隔符 (-
)(至少对于我的本地时间/设置)实际上不是必需的,一些括号,以及日期可以是数字:
=0+1&A1:A2&B1:B2
输出是日期类型(数字),然后你可以按照你的偏好格式化它,或使用 TEXT
函数:
=TEXT(0+("1-"&A1&"-"&B1),"mmm-yy")
其中 29221
是日期 1980年1月1日
的数值表示。正如你所看到的,它可以在数组形式下工作,因此你可以使用类似的方法转换一个范围。以下方法也有效:0+TEXTJOIN("-",,"1",A1,B1)
,但不适用于范围,你需要拖动它。
英文:
You can take advantage of how Excel casts strings as dates, based on your local/time settings. Assuming you have the month in cell A1
and the year in cell B1
:
=0+("1-"&A1&"-"&B1)
Note: later I found out that the dash delimiter (-
), at least for my local time/settings) is not really needed and some parenthesis, as well as the day one can be a number:
=0+1&A1:A2&B1:B2
The output is a date type (number), then you can format it in a date format of your preference or use the TEXT
function:
=TEXT(0+("1-"&A1&"-"&B1),"mmm-yy")
where 29221
is the numeric representation of the date: 1-Jan-1980
. As you can see it works in array form, so you can convert a range using a similar approach. The following also works: 0+TEXTJOIN("-",,"1",A1,B1)
but not for a range, you need to drag it down.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论