Solved

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

Posted on 2014-01-07
4
1,339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

696 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