Solved

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

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Generate Scripts Fails 5 36
T-SQL: Episode III - Revenge of The Dude 24 53
SQL Server 2012 r2 - Sum totals 2 25
SQL Server 2012 r2 - Varible Table 3 24
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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…

770 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