visual-foxpro - Visual FoxPro 字符串到日期的转换

标签 visual-foxpro string-to-datetime

如何将字符串 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/

相关文章:

java - 将字符串解析为日期格式

datetime - 如何在BigQuery中将dd/mm/yyyy字符串转换为日期?

php - 在 PHP SQL 查询中使用 STR_to_DATE

C# 从 .DBF 文件读取到数据表

visual-foxpro - 如何在 FoxPro 中使用 'update where' 选择?

foxpro - 将数字转换为字符

python - 替换日期中的日期以适应 pd.to_datetime 格式

java - 在 Java 中使用 STR_TO_DATE 插入日期,使用 PreparedStatement

mysql - 单向数据库同步到 MySQL

visual-foxpro - VFP 中是否有替代 MySQL Field() 函数的方法?