在vb脚本中获取MMDDYYYY格式

时间:2013-04-26 02:31:05

标签: vb.net vbscript

我有一个名为venkat_file的源文件。我需要将文件存档到存档文件夹中,同时将文件附加到此格式venkat_file_MMDDYYY。如果月份和日期值小于10,我想要使用特定值存档文件,

之前的示例:venkat_file,示例日期4/26/2013,现在我需要归档文件,使其如下所示:venkat_file_04262013,而不是venkat_file_4262013

提前致谢,

Venkat。

2 个答案:

答案 0 :(得分: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())

答案 1 :(得分: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>
相关问题