January 31, 2013 at 4:50 pm
I'm stumped. I have a script task for getting some files from an intranet site, then posting them to an archive FTP Location with a datestamp (mmddyyyy) appended. But the mm part isn't what I want - if it's a single digit month I want to pad the start with "0". Here's the snippet of what I'm doing:
Dim myHttpConnection = "HTTP Connection FTTN"
Dim my107URL = "\\66.136.94.107\FTP\FTP_SOG\Working\"
Dim myCA1URL = "\\CAFRFD1LTSPIA01\vp_gm_report\STAGING\"
Dim tmm = DatePart("m", Now)
Dim tdd = DatePart("d", Now)
Dim fileDate = DatePart("yyyy", Now)
Dim filesys = CreateObject("Scripting.FileSystemObject")
Dim myDestFile = "VP-GM Report"
If tdd < 10 Then
fileDate = "0" & tdd & fileDate
Else
fileDate = tdd & fileDate
End If
If tmm < 10 Then
fileDate = "0" & tmm & fileDate
Else
fileDate = tmm & fileDate
End If
' at this point the date should be 01312013
Dim myArchiveFile = myDestFile & "_" & fileDate & ".txt"
' and the file should be VP-GM Report_01312013.txt
But it's coming out like this: VP-GM Report_1312013.txt
Any suggestions as towhat I'm doing wrong? A similar code piece in activeX scripting worked OK
February 1, 2013 at 12:13 am
Try assigning a datatype to your variables, you would get less issues like this.
Datepart returns an integer value, so tmm is of type Integer. In your concatenation, fileDate is implicitly converting to an integer, so the leading zero is dropped.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
February 1, 2013 at 8:53 am
That was it! Sometimes it's the simple things that elude you 😀
There were 2 of us looking at it and we both missed that - and the other guy has tons of VB experience - unlike me
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply