2014-11-14 75 views
1

如何將字符串/ varchar轉換爲MonetDB中的時間戳?將字符串轉換爲MonetDB中的時間戳

這樣,但精確到毫秒(6位小數,理想情況下):

sql>select str_to_date('2008-09-19-18.40.09.812000', '%Y-%m-%d-%H.%M.%6S'); 
+--------------------------+ 
| str_to_date_single_value | 
+==========================+ 
| 2008-09-19    | 
+--------------------------+ 
1 tuple (0.312ms) 

我不知道是否STR_TO_DATE內置或是否我創造了它很久很久以前,忘了。

create function str_to_date(s string, format string) returns date 
external name mtime."str_to_date"; 

編輯:預期的輸出類似

+---------------------------------+ 
| str_to_timestamp_single_value | 
+=================================+ 
| 2008-09-19 18:40:09.812000  | 
+---------------------------------+ 

回答

1

Monetdb時間轉換函數中列出:

  • [Monetdb安裝文件夾] \ monetDB5 \ LIB \ monetdb5 \ CREATEDB \ 13_date.sql。

除了str_to_date函數,還有一個str_to_timestamp函數。

格式字符串的語法如下the MySQL one

例子:

select sys.str_to_timestamp('2016-02-04 15:30:29', '%Y-%m-%d %H:%M:%S'); 
+0

對於monet v1.7,它會拋出'沒有這樣的二元運算符'錯誤。在函數名'select sys.str_to_timestamp'前添加模式名稱 – redexp 2016-02-20 07:12:07

+0

感謝您的信息,我會更新我的答案。 – 2016-02-22 08:21:20

0

的日期/時間說明符可能需要改變:

select str_to_date('2008-09-19-18.40.09.812000','%Y-%m-%d-%H.%i.%s.%f') 

輸出:

2008-09-19 18:40:09.812000 

* monetdb可能不同,儘管在標準SQL these are the standard date specifiers中。

你也可以使用date_format除了str_to_date

select date_format(str_to_date('SEP 19 2008 06:40:09:812PM','%M %D %Y %h:%i:%s:%f%p'),'%Y-%m-%d-%H.%i.%f'); 

輸出:

2008-09-19-18.40.812000 
+0

日期/時間說明符都很好,我真的尋找類似'str_to_timestamp'。 – nacnudus 2014-11-15 02:26:31

+0

那麼monetdb有處理精確時間的叫做'daytime'。如果我沒有記錯的話就像'daytime_tz_fromstr'。我想我有點不清楚,你的預期輸出是什麼? – 2014-11-15 02:29:43

相關問題