dbTalk Databases Forums  

Date validation script

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


Discuss Date validation script in the microsoft.public.sqlserver.dts forum.



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

Default Date validation script - 04-11-2005 , 11:12 AM






I'm trying to convert date text to date time. I can use dateserial
sucessfully as shown below, however it is not uncommon to receive bad dates
in my data feed. Iv'e done a test and added 20051145 as a bad date, but
dateserial converts is to 12/15/2005 (just adds the days).


dim v_Day
dim v_Month
dim v_Year


v_Day = Cint(Mid( DTSSource("col001") ,7 , 2 ))
v_Month = Cint(Mid( DTSSource("col001") ,5 , 2 ))
v_Year = Cint(Left(DTSSource("col001"),4))

IF ISDATE(v_day+v_month+v_year)) then

DTSDestination("my_date") = DateSerial( v_Year , v_Month ,v_Day )

ELSE DTSDestination("my_date") = null

END IF


How can I validate and convert?

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

Default Re: Date validation script - 04-11-2005 , 01:11 PM






What about

If v_month < 1 OR v_Month > 12

For v_Days check against the month

Or you could use ISDATE(< expression >)


Allan

"Gary" <Gary (AT) discussions (DOT) microsoft.com> wrote


Quote:
I'm trying to convert date text to date time. I can use dateserial
sucessfully as shown below, however it is not uncommon to receive bad dates
in my data feed. Iv'e done a test and added 20051145 as a bad date, but
dateserial converts is to 12/15/2005 (just adds the days).


dim v_Day
dim v_Month
dim v_Year


v_Day = Cint(Mid( DTSSource("col001") ,7 , 2 ))
v_Month = Cint(Mid( DTSSource("col001") ,5 , 2 ))
v_Year = Cint(Left(DTSSource("col001"),4))

IF ISDATE(v_day+v_month+v_year)) then

DTSDestination("my_date") = DateSerial( v_Year , v_Month ,v_Day )

ELSE DTSDestination("my_date") = null

END IF


How can I validate and convert?


Reply With Quote
  #3  
Old   
Gary
 
Posts: n/a

Default Re: Date validation script - 04-11-2005 , 02:04 PM



Thanks for your reply Alan.

I would like to do it using isdate but when I use: ISDATE((v_month & v_day &
v_year)) , it always comes out false???

I also tried "v_year..mm..dd".

I also tried using the ISDATE directly on the source data which is the
proper usage for ISDATE(col001), still always false.

Suggestions...

"Allan Mitchell" wrote:

Quote:
What about

If v_month < 1 OR v_Month > 12

For v_Days check against the month

Or you could use ISDATE(< expression >)


Allan

"Gary" <Gary (AT) discussions (DOT) microsoft.com> wrote in message
news:Gary (AT) discussions (DOT) microsoft.com:

I'm trying to convert date text to date time. I can use dateserial
sucessfully as shown below, however it is not uncommon to receive bad dates
in my data feed. Iv'e done a test and added 20051145 as a bad date, but
dateserial converts is to 12/15/2005 (just adds the days).


dim v_Day
dim v_Month
dim v_Year


v_Day = Cint(Mid( DTSSource("col001") ,7 , 2 ))
v_Month = Cint(Mid( DTSSource("col001") ,5 , 2 ))
v_Year = Cint(Left(DTSSource("col001"),4))

IF ISDATE(v_day+v_month+v_year)) then

DTSDestination("my_date") = DateSerial( v_Year , v_Month ,v_Day )

ELSE DTSDestination("my_date") = null

END IF


How can I validate and convert?



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

Default Re: Date validation script - 04-11-2005 , 02:19 PM



It worked for me in the format

"DD/MM/YYYY"





"Gary" <Gary (AT) discussions (DOT) microsoft.com> wrote


Quote:
Thanks for your reply Alan.

I would like to do it using isdate but when I use: ISDATE((v_month & v_day &
v_year)) , it always comes out false???

I also tried "v_year..mm..dd".

I also tried using the ISDATE directly on the source data which is the
proper usage for ISDATE(col001), still always false.

Suggestions...

"Allan Mitchell" wrote:

What about

If v_month < 1 OR v_Month > 12

For v_Days check against the month

Or you could use ISDATE(< expression >)


Allan

"Gary" <Gary (AT) discussions (DOT) microsoft.com> wrote in message
news:Gary (AT) discussions (DOT) microsoft.com:

I'm trying to convert date text to date time. I can use dateserial
sucessfully as shown below, however it is not uncommon to receive bad dates
in my data feed. Iv'e done a test and added 20051145 as a bad date, but
dateserial converts is to 12/15/2005 (just adds the days).


dim v_Day
dim v_Month
dim v_Year


v_Day = Cint(Mid( DTSSource("col001") ,7 , 2 ))
v_Month = Cint(Mid( DTSSource("col001") ,5 , 2 ))
v_Year = Cint(Left(DTSSource("col001"),4))

IF ISDATE(v_day+v_month+v_year)) then

DTSDestination("my_date") = DateSerial( v_Year , v_Month ,v_Day )

ELSE DTSDestination("my_date") = null

END IF


How can I validate and convert?




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.