Solved

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

Posted on 2014-01-07
4
1,174 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

912 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now