![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all I'm trying to get 3 single integer values into a datetime field on my sql server. I'm using DTS ActivX Script Transformation and Visual Basic. When I test the Script i get the correct datetime format. But when i then go to the table on the sql server my date is sometimes in the wrong format... I use the following code: '************************************************* ********************* ' Visual Basic Transformation Script '************************************************* *********************** ' Copy each source column to the destination column Function Main() Dim tt Dim mm Dim jjjj Dim date if DTSSource("PENDD") = "0" OR DTSSource("PENMM") = "0" OR DTSSource("PENYYYY") = "0" then DTSDestination("PENDAT") = null else dd = CStr(DTSSource("PENDD")) mm = CStr(DTSSource("PENMM")) yyyy = CStr(DTSSource("PENYYYY")) date = mm + "/" + dd + "/" + yyyy DTSDestination("PENDAT") = date end if Main = DTSTransformStat_OK End Function When i Test my Code with the following values: DD =4 MM =5 YYYY = 2000 Format: mm/dd/yyyy Returns : 5/4/2000 But in the sql Server it is shown as 5.4.2000 . Cause I'm in a german language environment the Format should be dd.mm.yyyy ...but its like mm.dd.yyyy in this case. If I have values like: DD = 20 MM = 5 YYYY = 2000 Returns 5/20/2000 And also in My SQL Server the Values are correct with 20.5.2000 ... what am I doing wrong?? Is this an error in sql server? how can i do it right? thanks for your help Michael |
#3
| |||
| |||
|
|
Hi all I'm trying to get 3 single integer values into a datetime field on my sql server. I'm using DTS ActivX Script Transformation and Visual Basic. When I test the Script i get the correct datetime format. But when i then go to the table on the sql server my date is sometimes in the wrong format... I use the following code: '************************************************* ********************* ' Visual Basic Transformation Script '************************************************* *********************** ' Copy each source column to the destination column Function Main() Dim tt Dim mm Dim jjjj Dim date if DTSSource("PENDD") = "0" OR DTSSource("PENMM") = "0" OR DTSSource("PENYYYY") = "0" then DTSDestination("PENDAT") = null else dd = CStr(DTSSource("PENDD")) mm = CStr(DTSSource("PENMM")) yyyy = CStr(DTSSource("PENYYYY")) date = mm + "/" + dd + "/" + yyyy DTSDestination("PENDAT") = date end if Main = DTSTransformStat_OK End Function When i Test my Code with the following values: DD =4 MM =5 YYYY = 2000 Format: mm/dd/yyyy Returns : 5/4/2000 But in the sql Server it is shown as 5.4.2000 . Cause I'm in a german language environment the Format should be dd.mm.yyyy ...but its like mm.dd.yyyy in this case. If I have values like: DD = 20 MM = 5 YYYY = 2000 Returns 5/20/2000 And also in My SQL Server the Values are correct with 20.5.2000 ... what am I doing wrong?? Is this an error in sql server? how can i do it right? thanks for your help Michael |
#4
| |||
| |||
|
|
Dates with separators are tricky because they are interpreted differently depending on the settings of your SQL Server. Instead of creating a string from the dateparts, and then saving that in a datetime column, you can create a date in one go from the dateparts with the VBScript function DateSerial. You only need to change one line in your code: date = DateSerial( yyyy , mm , dd ) -- Jacco Schalkwijk SQL Server MVP "m.ahrens" <mahrens (AT) discussions (DOT) microsoft.com> wrote in message news:A5B2E319-8F14-4EB3-9B6D-49571D07696B (AT) microsoft (DOT) com... Hi all I'm trying to get 3 single integer values into a datetime field on my sql server. I'm using DTS ActivX Script Transformation and Visual Basic. When I test the Script i get the correct datetime format. But when i then go to the table on the sql server my date is sometimes in the wrong format... I use the following code: '************************************************* ********************* ' Visual Basic Transformation Script '************************************************* *********************** ' Copy each source column to the destination column Function Main() Dim tt Dim mm Dim jjjj Dim date if DTSSource("PENDD") = "0" OR DTSSource("PENMM") = "0" OR DTSSource("PENYYYY") = "0" then DTSDestination("PENDAT") = null else dd = CStr(DTSSource("PENDD")) mm = CStr(DTSSource("PENMM")) yyyy = CStr(DTSSource("PENYYYY")) date = mm + "/" + dd + "/" + yyyy DTSDestination("PENDAT") = date end if Main = DTSTransformStat_OK End Function When i Test my Code with the following values: DD =4 MM =5 YYYY = 2000 Format: mm/dd/yyyy Returns : 5/4/2000 But in the sql Server it is shown as 5.4.2000 . Cause I'm in a german language environment the Format should be dd.mm.yyyy ...but its like mm.dd.yyyy in this case. If I have values like: DD = 20 MM = 5 YYYY = 2000 Returns 5/20/2000 And also in My SQL Server the Values are correct with 20.5.2000 ... what am I doing wrong?? Is this an error in sql server? how can i do it right? thanks for your help Michael |
![]() |
| Thread Tools | |
| Display Modes | |
| |