0

How can i Convert DateTime2 to DateTime from Stored Procedure Executed Result ? I have a procedure which will execute a dynamically formed sql statement which will have an output of various columns in which there are some datetime2 data types. How can I change that datetime2 to datetime because I haev to assign this procedure as data source to a crystal report but crystal report converts datetime2 to string and string can't do required logic in report. So I want the procedure to give datetime rather than datetime2.

I guess temp tables might help me but not sure how to proceed.. please help..

4

1 回答 1

1

假设 DateTime2 字段字符串看起来像它在 MS SQL/ISO 8601(请参阅datetime2 (Transact-SQL)):“2007-05-02T19:58:47.1234567”,您可以提取字符串的所需部分,然后使用CDateCDateTime将它们转换为日期或日期时间。

If IsDate(left({Results.DT2Field}, 10))
    Then
    CDate(left({Results.DT2Field}, 10));

或日期时间

If IsDateTime(left({Results.DT2Field}, 10) + " " + mid({Results.DT2Field},12,8))
    Then
    CDateTime(left({Results.DT2Field}, 10) + " " + mid({Results.DT2Field},12,8));

以上结果是您的转换值。

于 2013-03-21T21:35:09.033 回答