Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3787|回复: 2

关于英文简写日期的转换

[复制链接]
发表于 2019-7-6 22:33 | 显示全部楼层 |阅读模式
1学分
比如说有个inputbox的日期为25May2019,怎么输出为5/25/2019.有木有哪位大佬有好方法。小弟在此谢过。

发表于 2019-7-7 08:31 | 显示全部楼层
25May2019不行,可以是25/May/2019或者25-May-2019,然后可以有下面的转换:
1、用cdate函数转换,转换后的类型是日期,所以不能直接用msgbox直接显示,但可以放在单元格中:
Cells(1,1) = CDate("25/May/2019")
2、用format格式化,得到的是文本,可以直接用msgbox显示,也可以放在单元格中:
Cells(1,2) = Format("25/May/2019", "dd/mm/yyyy")
要用-连接符,就换成:
Cells(1,2) = Format("25/May/2019", "dd-m-yyyy")
回复

使用道具 举报

 楼主| 发表于 2019-7-8 20:50 | 显示全部楼层
hfwufanhf2006 发表于 2019-7-7 08:31
25May2019不行,可以是25/May/2019或者25-May-2019,然后可以有下面的转换:
1、用cdate函数转换,转换后 ...

谢谢,网上找到下面这段代码可以一用,就是创建函数有点麻烦。
Public Function fConvertDate(strDate As String) As Date
Dim bytDay As Byte
Dim intYear As Integer
Dim strMonth As String
Dim bytMonth As Byte

bytDay = Val(Left(strDate, 2))
intYear = CInt(Mid(strDate, 6, 4))
strMonth = UCase$(Mid(strDate, 3, 3))

bytMonth = Val(Switch(strMonth = "JAN", "1", strMonth = "FEB", "2", strMonth = "MAR", "3", _
               strMonth = "APR", "4", strMonth = "MAY", "5", strMonth = "JUN", "6", strMonth = "JUL", "7", _
               strMonth = "AUG", "8", strMonth = "SEP", "9", strMonth = "OCT", "10", strMonth = "NOV", "11", _
               strMonth = "DEC", "12"))

fConvertDate = DateSerial(intYear, bytMonth, bytDay)
End Function


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-26 23:32 , Processed in 0.289187 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表