SSIS-创建DateTime的脚本问题 [英] SSIS - Script Issue creating a DateTime
问题描述
我正在使用SSIS将数据从CSV文件上传到数据库中的表中。我尝试获取2个字符串(一个用于日期,另一个用于时间),并像这样连接它们:
I'm using SSIS to upload data from a CSV file to a table from my database. I try to get 2 strings (one is for the date, the other is for the time) and concat them like this :
string datsDateTime = String.Concat(Row.DATE, " ", Row.HEURE);
然后,我尝试这样解析:
Then, I try to parse it like this :
Row.DateTime = DateTime.ParseExact(datsDateTime, "dd/MM/yyyy HH:mm", null);
但这不起作用。当我尝试测试该脚本时,出现以下错误:
But it does not work. When I try to test this script, I got this error :
String was not recognized as a valid DateTime.
at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)
at ScriptMain.Input0_ProcessInputRow(Input0Buffer Row)
at UserComponent.Input0_ProcessInput(Input0Buffer Buffer)
at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer)
I '正在使用Visual Studio2008。对此有任何想法吗?
I'm using Visual Studio 2008. Any idea about it?
编辑:在我的csv文件中的日期列中, date是一个类似这样的字符串: 20120101 (2012,月份为01,日期为01)。
EDIT : In my column "date" which is in my csv file, the date is a string which is like this : 20120101 (2012, 01 for the month and 01 for the day).
UPDATE :好的,我通过执行以下操作找到了解决方案:
string datsDateTime = Row.DATE.Insert(6, /)。Insert(4, /) + + Row.HEURE;
,然后再粘贴任何内容。希望对您有所帮助。
UPDATE : Ok I found the solution by doing this
string datsDateTime = Row.DATE.Insert(6,"/").Insert(4, "/") + " " + Row.HEURE;
before pasing anything. Hope it'll help.
推荐答案
您应该将格式更改为
Row.FinalDate = DateTime.ParseExact(datsDateTime, "yyyyMMdd HH:mm", null);
由于您的获取日期采用 yyyymmdd
格式
日期不是以 string
的形式存储,而是以 integers
的形式存储。如果要以dd / mm显示数据/ yyyy格式,然后可以使用
Since your getting dates in yyyymmdd
format
Dates are stored not as string
but as integers
.If you want to display the data in dd/mm/yyyy format then you can use ToString() method with a specific format like
YourDate.ToString("dd/MM/yyyy")
但由于您存储在数据库中,因此它将存储为整数
检查SQL Server中的Dateformat
but since you are storing in your database then ,it will be stored as integers Check the Dateformat in your sql server
dbcc useroptions
这篇关于SSIS-创建DateTime的脚本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!