将月份编号(日期时间或4字节整数)转换为月份名称(字符串)SSIS [英] Converting Month Number(Date Time or 4 byte integer) to Month Name(String) SSIS
问题描述
我需要将月份号转换为月份名称.我将日期时间作为日期类型-2009-01-01 00:00:00.000我也有4字节整数数据类型-1
I need to convert month number to month name. I have date time as the date type - 2009-01-01 00:00:00.000 I also have 4-byte integer data type - 1
如何将此1转换为"January"例如?
how do I convert this 1 to "January" for example?
推荐答案
我认为您在数据流中:
从日期中的脚本组件中获得MOnth名称确实很容易:
it is really easy to get MOnth Name in a script component from Date:
-
将varchar列添加到您的数据流
add a varchar column to your dataflow
将您的日期列标记为只读
Mark your date column for read access
输入以下脚本
Row.[NewColumnName] = Row.[Your Date Column].ToString("MMMM");
结果:
以下是将日期部分转换为字符串格式的很好的翻译:
Here is a good translations for any date part to string formatting:
// create date time 2008-03-09 16:05:07.123
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year
String.Format("{0:M MM MMM MMMM}", dt); // "3 03 Mar March" month
String.Format("{0:d dd ddd dddd}", dt); // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}", dt); // "4 04 16 16" hour 12/24
String.Format("{0:m mm}", dt); // "5 05" minute
String.Format("{0:s ss}", dt); // "7 07" second
String.Format("{0:f ff fff ffff}", dt); // "1 12 123 1230" sec.fraction
String.Format("{0:F FF FFF FFFF}", dt); // "1 12 123 123" without zeroes
String.Format("{0:t tt}", dt); // "P PM" A.M. or P.M.
String.Format("{0:z zz zzz}", dt); // "-6 -06 -06:00" time zone
此外,您还询问了宿舍.我不认为这很容易,但这是我从另一个答案中偷走的东西.
Furthermore, you asked about quarters. I don't think it is as easy but here is something I stole from another answer.
构建DateTime扩展名:
Build DateTime extensions:
常规季度:
public static int GetQuarter(this DateTime date)
{
return (date.Month + 2)/3;
}
会计年度季度(此情况适用于从4月1日开始的季度):
public static int GetFinancialQuarter(this DateTime date)
{
return (date.AddMonths(-3).Month + 2)/3;
}
整数除法将截断小数,从而为您提供整数结果.将方法放到静态类中,您将具有如下扩展方法:
Integer division will truncate decimals, giving you an integer result. Place methods into a static class and you will have an extension method to be used as follows:
Row.calendarQuarter = Row.[your Date Column].GetQuarter()
Row.fiscalQuarter = Row.[your Date Column].GetFinancialQuarter()
这篇关于将月份编号(日期时间或4字节整数)转换为月份名称(字符串)SSIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!