我有一个制表符分隔的文字,我提取了它的数据,但我发现了转换某些日期的挑战,因为它们的格式不同,如1 AUG 1989
i' m将数据作为一个字符串,我循环遍历它以分解它并用它建立一个有效的日期
以下是我用空格分隔日期的代码("")感谢您的帮助
//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
答案 0 :(得分:1)
对于提供的当前格式,您可以使用:
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)
如果您需要有关其他格式的帮助,则需要提供它们。