datetoday = Now
strMonth = Month(datetoday)
strDay = Day(datetoday)
strHour = Hour(datetoday)
strMinute = Minute(datetoday)
strSecond = Second(datetoday)
if len(strMonth) = 1 Then
strMonth = "0" & strMonth
end If
if len(strDay) = 1 Then
strDay = "0" & strDay
end If
if len(strHour) = 1 Then
strHour = "0" & strHour
End If
If len(strMinute) = 1 Then
strMinute = "0" & strMinute
End If
If len(strSecond) = 1 Then
strSecond = "0" & strSecond
End If
datetoday = YEAR(datetoday) & strMonth & strDay
timetoday = strHour & strMinute & strSecond
strFile = datetoday & "_" & timetoday & ".zip"
FSO.CreateTextFile(strFile)
--
Thanks
TimM
This is about how I generally do it ...
datetoday = Now
strMonth = Right("0" & Month(datetoday) ,2)
strDay = Right("0" & Day(datetoday) ,2)
strHour = Right("0" & Hour(datetoday) ,2)
strMinute = Right("0" & Minute(datetoday),2)
strSecond = Right("0" & Second(datetoday),2)
datetoday = YEAR(datetoday) & strMonth & strDay
timetoday = strHour & strMinute & strSecond
strFile = datetoday & "_" & timetoday & ".zip"
FSO.CreateTextFile(strFile)
HTH
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
You could do it like so:
strFile = Year(Now) & Pad(Month(Now)) & Pad(Day(Now)) & "_" _
& Pad(Hour(Now)) & Pad(Minute(Now)) & Pad(Second(Now)) & ".zip"
FSO.CreateTextFile("d:\" & strFile)
Function Pad(n)
If n < 10 Then
Pad = "0" & n
Else
Pad = n
End If
End Function
Presuming you want "yyyymmdd_hhnnss.zip", then:
dtm = Now
ymd = (Year(dtm)*10000) + (Month(dtm)*100) + Day(dtm)
hms = (Hour(dtm)*10000) + (Minute(dtm)*100) + Second(dtm)
strFile = ymd & "_" & hms & ".zip"
FSO.CreateTextFile(strFile)
'' DNIPrintF( sFmt, aItems ) - use .NET to sprintf()
' ----------------------------------------------------------------------------
Function DNIPrintF( sFmt, aItems )
Dim oSB : Set oSB = CreateObject( "System.Text.StringBuilder" )
oSB.AppendFormat_4 sFmt, (aItems)
DNIPrintF = oSB.ToString()
End Function
to solve you problem like this:
Dim sFiNa : sFina = DNIPrintF( "{0:yyyyMMdd-HHmmss}.zip", Array( Now() ) )
Of course, after that you won't have to do other formatting/complex
concatenation tasks 'by hand' evermore.