Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add leading zero to Hour/Minute in a VBScript in DTS Package

Status
Not open for further replies.

mitchelt

Technical User
Jul 30, 2001
21
US
Hi,

I am creating a DTS package and in one of the steps the file that is created is automatically renamed using the current data and time. The problem is that the HOUR and MINUTES are coming in as single digits and dropping the leading zero, which of course I need.

Below is the code that I am using, I've tried various methods of getting the leading zero to show up back I cannot get it.

Any help would be greatly appreciated.

Thanks,

Mitch

'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()

Dim FileDate
Dim DateString
Dim FSO
Dim File

FileDate = Date
DateString = DatePart("yyyy",FileDate) & Right("0" & _
DatePart("m",FileDate), 2) & Right("0" & DatePart("d",FileDate), 2) & _
Hour(Now) & Minute(Now)

Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.GetFile("c:\temp\suo_test_2.txt")
File.Name = "test" & DateString & ".txt"

Main = DTSTaskExecResult_Success
End Function
 
use the convert function after you get month/day/hour from datepart to a varchar field.

something like this:
Code:
select right('0' + convert(varchar, month(getdate())), 2)

Regards,
AA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top