views:

319

answers:

2

How to convert LastModifiedTime value of MssCrawlUrl table ?

I tried below query,

Select CAST(LastModifiedTime as datetime)
From MssCrawlUrl Where DisplayURL like '<DisplayURL>'

But it is giving an error

'Arithmetic overflow error converting expression to data type datetime.'

+1  A: 

It is not supported to query the SharePoint databases directly. You must use the API. Apart from the official "not supported" reason, it can cause locking, return incorrect data, and custom queries may break between service packs or product versions. See Mike Fitz's post Please Stay Out Of The Database! from his time at Microsoft.

See this Visual How To for an example of how to use the supported API. Also see these articles on MSDN and this best practices article for further information.

Alex Angas
Exactly, even a simple SELECT can put a lock on a table, which might lead to unforseen results in the actual site(s) itself / themselves.
Colin
I know how to do that with SharePoint API. What I want is query the database. What you are trying to explain that is fine. I completely understand your concern. I will take care of database for its consistency.Do you have any idea how can I get lastmodifieddate of a document from database directly wi the help of query?
Ravi Khambhati
@Ravi: OK I see you asked a similar question yesterday and I gave the same answer. If you **absolutely must** do this please use NOLOCK or equivalent everywhere. As can be seen from the schema this is stored as a bigint. In .NET it's probably used with the DateTime(Int64) constructor. Can't help with conversion within Transact-SQL sorry.
Alex Angas
A: 

I got the ans

DECLARE @dt AS bigint
SET @dt = <BIGINT>
SELECT DATEADD(ms, (@dt / CAST(10000 AS bigint)) % 86400000,
DATEADD(day, @dt / CAST(864000000000 AS bigint) - 109207, 0))
Ravi Khambhati