2013-04-26 48 views
0

我有一個名爲venkat_file的源文件。我需要將文件歸檔到歸檔文件夾中,同時將文件追加到此格式venkat_file_MMDDYYY。如果月份和日期值小於10,我想之前存檔與特定值的文件,在vb腳本中獲取MMDDYYYY格式

例子:venkat_file,例如日期4/26/2013,現在我需要對該文件進行歸檔,所以它看起來是這樣的:venkat_file_04262013,而不是venkat_file_4262013

在此先感謝,

Venkat。

回答

0

可以使用追加日期以下

Dim ThisDate as string 
' 
ThisDate = format(now.month,"00") & format(now.day,"00") & format(now.year,"0000") 

更新

由於Raybiss指出它不是VBSCRIPT。 所以我把vbscript放在下面。

<script type="text/vbscript" id="ArchiveFile"> 
' <!-- 
Function GetNewArchiveFilename(ThisFile) 
' 
Dim ThisDay, ThisMonth, ThisYear 
Dim ThisFName 
' 
    ThisDay = day(date) 
    ThisMonth = month(date) 
    ThisYear = year(date) 
    ThisFName = Left(Thisfile, len(thisfile)-4) & FormatNumber(Thisday,0,-1) & formatnumber(Thismonth,0,-1) & formatnumber(thisyear,0,0,0,0) & right(thisfile,4) 
    'msgbox(thisfname) 
    return thisfname 
' 
End Function 
' --> 
</script> 
+0

這將是VB/VBA但不是的VBScript – raybiss 2013-04-26 02:46:28

2

你可以有這樣一個功能:

Function FormatNum(n, totalDigits) 
    If totalDigits > Len(n) Then 
     FormatNum = String(totalDigits - Len(n),"0") & n 
    Else 
     FormatNum = n 
    End if 
End Function 

而且使用這樣的:

s = FormatNum(Month(Date()) , 2) & _ 
    FormatNum(Day(Date()), 2) & _ 
    Year(Date())