gpt4 book ai didi

SSIS 填充日期时间格式 : "hh mm ss nnn cc yy mm dd"

转载 作者:行者123 更新时间:2023-12-01 18:03:49 25 4
gpt4 key购买 nike

这可能是一个非常简单的问题,但是:

我正在尝试将文件命名为 TestSheet.hhmmssnnnccyymmdd

我在 SSIS 中设置了一个变量,并且表达式生成器中的表达式设置为:

@[用户::str_Var] +
Right("0"+ (DT_STR,4,1252) DatePart("hh",getdate()),2) +
右("0"+ (DT_STR,4,1252) DatePart("mi",getdate()),2) +
Right("0"+ (DT_STR,4,1252) DatePart("ss",getdate()),2) + ".txt"

我知道:

Right("0"+ (DT_STR,4,1252) DatePart("m",getdate()),2) +
Right("0"+ (DT_STR,4,1252) DatePart("d",getdate()),2)

会给我“mm”和dd“

我的问题是..我有“hh mm ss mm dd”,我如何获得“nnnccyy”?

最佳答案

即使您要求纳秒(十亿分之一),我假设您的意思是毫秒(千分之一)精度。 DATEPART仅提供毫秒精度的切片器。

使用表达式,构建格式字符串的位将如下所示

Right("0" + (DT_STR,2,1252) DatePart("hh",getdate()),2) 
+ Right("0" + (DT_STR,2,1252) DatePart("mi",getdate()),2)
+ Right("0" + (DT_STR,4,1252) DatePart("ss",getdate()),2)
+ Right("000" + (DT_STR,3,1252) datepart("Ms", getdate()),3)
+ (DT_STR,4,1252) datepart("yyyy", getdate())
+ (DT_STR,2,1252) datepart("mm", getdate())
+ (DT_STR,2,1252) datepart("dd", getdate())

我不知道 getdate 内部是如何工作的,但在研究中我确实发现了这个问题 What is the best way to measure how long code takes to execute?但我认为它基本上是调用来自 Eric Lippert 的 DateTime.Now Money 报价,但这一个是最相关的。

Note that "wall clock time" measured by DateTime is only accurate to something like 30 ms. DateTime is for representing things like a clock on the wall, or the time you last edited a file; it doens't have to have nanosecond accuracy, and so it does not

如果你必须达到纳秒精度,那么快乐狩猎,但表达式不会解决它。正如 @fegemo 所指出的,脚本任务可以让您达到百万分之一 custom formatting但这距离您期望的精度仍然有两个数量级。

this.Dts.Variables["User::CustomFormat"].Value = DateTime.Now.ToString("HHmmssfffffyyyyMMdd");

关于SSIS 填充日期时间格式 : "hh mm ss nnn cc yy mm dd",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13650927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com