all groups > sql server dts > june 2005 >
You're in the

sql server dts

group:

datepart failing why?


datepart failing why? mo
6/21/2005 3:44:47 PM
sql server dts:
Simple portion of an active x script in SQL Server 2000 is failing on
"mm" and "dd". It works with m and d

DTSGlobalVariables("gstrToday").Value = DatePart("yyyy", Now()) &
DatePart("mm", Now()) & DatePart("dd", Now())
tia Moe
RE: datepart failing why? Ed
6/21/2005 4:15:02 PM
This is how it works for DatePart in VB Script
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second

Hope this helps...

Ed


[quoted text, click to view]
Re: datepart failing why? mo
6/22/2005 9:50:16 AM
Thanks anyway! but it didn't answer the question of how to get a two
digit month (as m yields 6 when I need 06)

The SQL server solution of select CONVERT(char(8), Getdate(), 112)
wouldn't run.

Here's what I did:
'explicitly format month to two digits
If Len(DatePart("m", Now())) =1 Then
strMonth = "0" & DatePart("m", Now())
Else strMonth = DatePart("m", Now())
End If

'explicitly format day to two digits
If Len(DatePart("d", Now())) =1 Then
strDay = "0" & DatePart("d", Now())
Else strDay = DatePart("d", Now())
End If

DTSGlobalVariables("gstrToday").Value = DatePart("yyyy", Now()) &
strMonth & strDay
Re: datepart failing why? Darren Green
6/23/2005 12:01:38 PM
A slightly less verbose method of getting two digit dates-

strMonth = Right("0" & DatePart("m", Now()), 2)


--
Darren Green
http://www.sqldts.com
http://www.sqlis.com


[quoted text, click to view]

AddThis Social Bookmark Button