Solved

How the record "nDateTime"  in table  TB_EVENT_LOG is written?

Posted on 2014-01-07
4
1,249 Views
Last Modified: 2014-01-21
I have this SQL Database, the record nDateTime in  TB_EVENT_LOG Table is saved in a way that I cant understand, can anyone tell me how it is saved so I can read it-
In the Views -->IBA_Transactions...I cant read all the records clearly "Date-Time"
I attach the database, just unzip and add the ext .bak
Thanks
2014.zip
0
Comment
Question by:Ihab
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Habib Pourfard
ID: 39764361
instead of storing datetime values, they are storing seconds since 1970-01-01. as you can see in the view you need to decode it:

SELECT TOP 1000
        [nEventLogIdn] ,
        CONVERT(NVARCHAR(32), DATEADD(s, TB_EVENT_LOG.nDateTime, '1970-01-01'), 111) AS [Date] ,
        CONVERT(NVARCHAR(32), DATEADD(s, TB_EVENT_LOG.nDateTime, '1970-01-01'), 108) AS [Time]
FROM    [BioStar].[dbo].[TB_EVENT_LOG]

Open in new window


I have no idea why they are storing date data as int instead of datetime.
0
 

Author Comment

by:Ihab
ID: 39764365
Thanks Mr. Pour
But I didnt get the idea , Please can you explain more?
0
 

Author Comment

by:Ihab
ID: 39764372
I need to edit a data and time, How I can do this in the SQL Server Management Studio 2008?
0
 
LVL 12

Accepted Solution

by:
Habib Pourfard earned 500 total points
ID: 39764379
To convert datetime to int, you need to find difference between '1970-01-01' and your desired date in seconds:

SELECT DATEDIFF(s, '1970-01-01', '2001/01/01 00:02:22')
--RETURNS 978307342

Open in new window


To Convert int to datetime, you need to add seconds to '1970-01-01' to get your desired date:

SELECT DATEADD(s, 978307342, '1970-01-01')
--RETURNS 2001-01-01 00:02:22

Open in new window


To update:
DECLARE @date DATETIME = '2001/01/01 00:02:22'
UPDATE  dbo.TB_EVENT_LOG
SET     nDateTime = DATEDIFF(s, '1970-01-01', @date)
WHERE   nEventIdn = @Id

Open in new window

0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question