如何从字符串日期中提取月份?

How To Extract a Month From a String Date?

我有一个制表符分隔的文本,我正在提取它的数据,但我发现转换一些日期时遇到了挑战,因为它们的格式与此不同 1 AUG 1989 我将数据作为字符串,我循环遍历它以分解它并用它构建一个有效日期 这是我的日期代码,用 Space(" ") 分隔,感谢您的帮助

//Extract the day 
ll_strtsearch = 1 
ll_fsearch = Pos(ls_tmp ," " , ll_strtsearch)
ll_len = ll_fsearch - ll_strtsearch 
ls_tmpdate = Trim(Mid(ls_tmp , ll_strtsearch , ll_len )) 
ll_day = Long(ls_tmpdate)

//Extract the Month
ll_strtsearch = ll_fsearch + 1 
ll_fsearch = Pos(ls_tmp , " " , ll_strtsearch)
ll_len = ll_fsearch - ll_strtsearch
ls_tmpdate = Trim(Mid(ls_tmp , ll_strtsearch , ll_len)) 
ll_month = Month(ld_tmp)
//ll_month = Long(ls_tmpdate) 


//Extract the Year 
ll_strtsearch = ll_fsearch + 1 
ll_len = 4
setNull(ld_empDob)
ls_tmpdate = Trim(Mid(ls_tmp , ll_strtsearch , ll_len)) 
if len(ls_tmpdate) = 4 Then
    ll_year = Long(ls_tmpdate)
Else 
    If len(ls_tmpdate) = 2 Then 
        ls_tmpdate = "19" + ls_tmpdate 
        ld_empDob = Date(Long(ls_tmp) , 1 ,1 )
    End If 

对于当前提供的格式,您可以使用此格式:

long ll_day,ll_month,ll_year

ls_tmp = '1 AUG 1989' // d mmm yyyy 
ll_day = Day(date(ls_tmp))
ll_month = Month(date(ls_tmp))
ll_year = Year(date(ls_tmp))

如果您想继续使用您的代码,请在月份的情况下更改此设置:

//Extract the Month
ll_strtsearch = ll_fsearch + 1 
ll_fsearch = Pos(ls_tmp , " " , ll_strtsearch)
ll_len = ll_fsearch - ll_strtsearch
ls_tmpdate = Trim(Mid(ls_tmp , ll_strtsearch , ll_len)) 
ll_month = Month(date(ls_tmp))
//ll_month = Long(ls_tmpdate) 

如果您需要有关其他格式的帮助,请提供。