SQL 在 Informix DB 中将字符串转换为日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21123323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert String to Date in Informix DB
提问by user2760011
I need to Convert a string say '12/12/2013 14:30:56.583' to be converted in Date Format like 2013-12-12 14:30:56.583 in Informix database.
我需要转换一个字符串,比如 '12/12/2013 14:30:56.583' 以日期格式转换,如 Informix 数据库中的 2013-12-12 14:30:56.583。
I Used following function
我使用了以下功能
to_date('12/12/2013 14:30:56.583',"%d/%m/%Y %H:%M:%S.")
But its not accepting Milliseconds , Milliseconds are important to the resulting value.
但它不接受 Milliseconds , Milliseconds 对结果值很重要。
回答by Fernando Nunes
The database version is important. The behaviour of %F was recently (11.70.xC8 and 12.10.xC2) changed. In previous versions the "." dot must probably be omitted as well as the "n" qualifier. Regards
数据库版本很重要。%F 的行为最近(11.70.xC8 和 12.10.xC2)发生了变化。在以前的版本中,“.” 点和“n”限定符可能必须被省略。问候
回答by ceinmart
If you check the manual you will see is missing the milliseconds at the string format.
如果您查看手册,您会发现字符串格式缺少毫秒。
来源:http: //www-01.ibm.com/support/knowledgecenter/api/content/SSGU8G_12.1.0/com.ibm.sqls.doc/ids_sqs_1542.htm
%S Second as a 2-digit integer (00 through 61). The second value can be up to 61 (instead of 59) to allow for the occasional leap second and double leap second.
%Fn The value of the fraction of a second, with precision specified by the unsigned integer n. The default value of n is 2; the range of n is 0 ≤ n ≤ 5. This value overrides any width or precision that is specified between the % and F characters.
%S 秒为 2 位整数(00 到 61)。第二个值最多可以是 61(而不是 59),以允许偶尔出现闰秒和双闰秒。
%Fn 秒的小数部分的值,精度由无符号整数 n 指定。n 的默认值为 2;n 的范围是 0 ≤ n ≤ 5。该值会覆盖在 % 和 F 字符之间指定的任何宽度或精度。
So, this probably will work:
所以,这可能会奏效:
to_date('12/12/2013 14:30:56.583',"%d/%m/%Y %H:%M:%S.%F3")
回答by Seymour
I'm not that familiar with Informix, but I think you may be able to use the standard to_date function to convert the string value to a date and then use an addMilliseconds function to add the milliseconds.
我对 Informix 不太熟悉,但我认为您可以使用标准的 to_date 函数将字符串值转换为日期,然后使用 addMilliseconds 函数来添加毫秒。