在 MS Access 中将字符串转换为日期格式
Converting String to Date format in MS Access
我有一个以字符串格式显示月份和年份的字段。如何在 Microsoft Access 中将其转换为 MMYYYY 格式?
字段值如下:
Period Code
M01-15
M02-15
M03-15
M04-15
M05-15
以上数值由客户端发送。
我想获取任何日期格式的值,最好是 MMYYYY。
结果应为:
Period Code
012015
022015
032015
042015
052015
谁能告诉我怎样才能得到想要的结果?
您可以使用 DateSerial 和格式:
MDate = "M03-15"
MonthYear = Format(DateSerial(Mid(MDate, 5), Mid(MDate, 2, 2), 1), "mmyyyy")
' Returns: 032015
或用替换暴力破解:
MDate = "M04-15"
MonthYear = Replace(Mid(MDate, 2), "-", "20")
' Returns: 042015
我有一个以字符串格式显示月份和年份的字段。如何在 Microsoft Access 中将其转换为 MMYYYY 格式?
字段值如下:
Period Code
M01-15
M02-15
M03-15
M04-15
M05-15
以上数值由客户端发送。
我想获取任何日期格式的值,最好是 MMYYYY。
结果应为:
Period Code
012015
022015
032015
042015
052015
谁能告诉我怎样才能得到想要的结果?
您可以使用 DateSerial 和格式:
MDate = "M03-15"
MonthYear = Format(DateSerial(Mid(MDate, 5), Mid(MDate, 2, 2), 1), "mmyyyy")
' Returns: 032015
或用替换暴力破解:
MDate = "M04-15"
MonthYear = Replace(Mid(MDate, 2), "-", "20")
' Returns: 042015