dbTalk Databases Forums  

ActiveX script converting to datetime syntax

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss ActiveX script converting to datetime syntax in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Olivia
 
Posts: n/a

Default ActiveX script converting to datetime syntax - 03-02-2004 , 12:18 PM






What is the syntax to convert varchar to datetime in
ActiveX? Again, my source field is varchar and destination
field is datetime. I tried using CDate and it didn't work.
I'm not very familiar with ActiveX. Thanks in advance for
your help.

Function Main()
DTSDestination(CDate("COL1")) = DTSSource("COL1")
Main = DTSTransformStat_OK
End Function

Reply With Quote
  #2  
Old   
Darren Green
 
Posts: n/a

Default Re: ActiveX script converting to datetime syntax - 03-02-2004 , 12:25 PM






In message <59e101c40082$b4d34670$a001280a (AT) phx (DOT) gbl>, Olivia
<anonymous (AT) discussions (DOT) microsoft.com> writes
Quote:
What is the syntax to convert varchar to datetime in
ActiveX? Again, my source field is varchar and destination
field is datetime. I tried using CDate and it didn't work.
I'm not very familiar with ActiveX. Thanks in advance for
your help.

Function Main()
DTSDestination(CDate("COL1")) = DTSSource("COL1")
Main = DTSTransformStat_OK
End Function
Try -

DTSDestination("COL1").Value = CDate(DTSSource("COL1").Value)

This still may not work because VBScript does not accept some string
formats that SQL for example would, e.g. yyyymmdd. If you varchar date
is something that VBScript does not like then you will need to perform
some string manipulation, using functions like Left, Right and Mid to
build up a suitable date format.

Write a simple test script in an ActiveX Script Task, e.g.

Dim sDate
Dim dDate

sDate = "20010101"
dDate = CDate(sDate)


The above will of course fail, but you can quickly test conversions in
this way.
--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
  #3  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: ActiveX script converting to datetime syntax - 03-02-2004 , 01:18 PM



I also like to use something like this

Formatting Character Data into Datetime fields
(http://www.sqldts.com/default.aspx?249)

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Darren Green" <darren.green (AT) reply-to-newsgroup-sqldts (DOT) com> wrote

Quote:
In message <59e101c40082$b4d34670$a001280a (AT) phx (DOT) gbl>, Olivia
anonymous (AT) discussions (DOT) microsoft.com> writes
What is the syntax to convert varchar to datetime in
ActiveX? Again, my source field is varchar and destination
field is datetime. I tried using CDate and it didn't work.
I'm not very familiar with ActiveX. Thanks in advance for
your help.

Function Main()
DTSDestination(CDate("COL1")) = DTSSource("COL1")
Main = DTSTransformStat_OK
End Function

Try -

DTSDestination("COL1").Value = CDate(DTSSource("COL1").Value)

This still may not work because VBScript does not accept some string
formats that SQL for example would, e.g. yyyymmdd. If you varchar date
is something that VBScript does not like then you will need to perform
some string manipulation, using functions like Left, Right and Mid to
build up a suitable date format.

Write a simple test script in an ActiveX Script Task, e.g.

Dim sDate
Dim dDate

sDate = "20010101"
dDate = CDate(sDate)


The above will of course fail, but you can quickly test conversions in
this way.
--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.