简体   繁体   English

SSIS - 日期格式的脚本组件 - VB.NET/C#

[英]SSIS - Script Component for Date Formatting - VB.NET/C#

so I have a situation where (via SSIS) I'm basically running a SELECT against my DB, and then exporting the results to a .txt flatfile. 所以我有一种情况(通过SSIS)我基本上对我的数据库运行SELECT,然后将结果导出到.txt平面文件。

The SSIS flow is as follows: OLEDB SOURCE (my select query) -> DATA CONVERSION (change all values to DT_WSTR) -> FLAT FILE DESTINATION SSIS流程如下:OLEDB SOURCE(我的选择查询) - > DATA CONVERSION(将所有值更改为DT_WSTR) - > FLAT FILE DESTINATION

However, I was told I need to change the format of all the datetime column values I export from the format of yyyy-mm-dd hh:nn:ss (what it is in the DB) to mm/dd/yyyy hh:nn:ss AM/PM 但是,有人告诉我需要更改我输出的所有日期时间列值的格式,格式为yyyy-mm-dd hh:nn:ss (数据库中的内容)为mm/dd/yyyy hh:nn:ss AM/PM

From my searching on this topic, I believe a script component between my DATA CONVERSION and FLAT FILE DESTINATION is what I need in SSIS....but I have no VB.NET or C# skills whatsoever. 从我对这个主题的搜索,我相信我的数据转换和平面文件目标之间的脚本组件是我在SSIS中所需要的......但我没有任何VB.NET或C#技能。 And despite searching, I have yet to really understand how I'd code this date formatting conversion up. 尽管搜索,我还没有真正理解我如何编码这个日期格式转换。

Help? 救命?

You can do the conversion in your SELECT statement. 您可以在SELECT语句中进行转换。

This will get your close: 这将结束你:

SELECT CONVERT(VARCHAR(20),GetDate(),101) + ' ' 
+ LTRIM(RIGHT(CONVERT(VARCHAR(26),GetDate(),9),14))

Just replace GetDate() with your date field. 只需将GetDate()替换为您的日期字段即可。 If you need it without the nanoseconds, it's a bit longer: 如果你需要它没有纳秒,它会更长一些:

SELECT CONVERT(VARCHAR(20),GetDate(),101) + ' ' 
+ LTRIM(LEFT(RIGHT(CONVERT(VARCHAR(26),GetDate(),9),14),8)) + ' ' 
+ RIGHT(CONVERT(VARCHAR(26),GetDate(),9),2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM