如何将字符串 30-Jul-17
转换为日期格式 07/30/17
?
最佳答案
我不相信 VFP 中有内置方法可以解析缩写的月份字符串(甚至完整的月份名称)。如果是我,我会像这样对每个缩写月份使用 CASE 语句。
lcStringDate = "30-Jul-17"
lcDay = LEFT(lcStringDate, 2)
lcMonth = SUBSTR(lcStringDate, 4, 3)
lcYear = "20"+RIGHT(lcStringDate, 2)
*!* Here you'd need to have code to convert abbreviated
*!* month to a numeric month
DO CASE
CASE lcMonth = "Jan"
lcNumericMonth = "1"
CASE lcMonth = "Feb"
lcNumericMonth = "2"
.
.
.
ENDCASE
?CTOD(lcNumericMonth+"/"+lcDay+"/"+lcYear)
*!* this would output "07/30/17" if SET CENTURY is OFF
*!* this would output "07/30/2017" if SET CENTURY is ON
关于visual-foxpro - Visual FoxPro 字符串到日期的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45594563/