[英]convert day of week, Month, day year to d/m/y
I have the following in excel: 我在excel中有以下内容:
Saturday, June 11 2011
I would like to convert this into the standard dd/mm/yy format. 我想将其转换为标准的dd / mm / yy格式。
What would be the easiest way to do this (in either excel or VBA)? 什么是最简单的方法(在excel或VBA中)?
In order to use Excel's CDate function , you first have to get rid of the leading text marking the day. 为了使用Excel的CDate函数 ,您首先必须摆脱标记日期的前导文本。 Assuming this is always with a trailing comma and space, you could do the following: 假设这始终带有逗号和空格,那么您可以执行以下操作:
Sub changedtformat()
Dim rawdate As String, cleandate As Date, resultdate As Date
rawdate = "Saturday, June 11 2011"
cleandate = Mid(rawdate, InStr(1, rawdate, ",") + 2, Len(rawdate))
resultdate = CDate(cleandate)
MsgBox resultdate
End Sub
With your text in A1 , in B1 enter: 将文本输入A1 ,然后在B1中输入:
=DATEVALUE(SUBSTITUTE(MID(A1,FIND(" ",A1)+1,9999)," ",", ",2))
and format anyway you like. 并按照自己喜欢的格式进行格式化。 We just make a string that DATEVALUE()
can handle. 我们只创建一个DATEVALUE()
可以处理的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.