SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Why is the real date in SQL different than in EXCEL


Why is the real date in SQL different than in EXCEL

Author
Message
peter2501
peter2501
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 63
Hi,

I want to calculate with Dates and Times in SQL, but I have noticed that if I do
Select CONVERT (real, Current_Timestamp), Current_timestamp
gives me this
41700.52 2014-03-04 12:31:29.830

And in Excel it is
41702.52 3/4/14 12:29

As you can see, Excel is two days further when the number is not a date.

What is the correct number for a date?

Next question is, how can I convert a current time into a more accurate numeric value. As I also want to calculate with time
example
Select (1/(SUM(Rows)/1846415)) * (CURRENT_TIMESTAMP - '2014-03-04 10:51:00.380')
does not work

Kind regards
Peter
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27587 Visits: 13268
I think the difference is due to the leap year bug in Excel:

http://www.ozgrid.com/Excel/ExcelDateandTimes.htm

Select (1/(SUM(Rows)/1846415)) * (CURRENT_TIMESTAMP - '2014-03-04 10:51:00.380')



This won't work as CURRENT_TIMESTAMP is Oracle and SUM(Rows) is not possible without a FROM clause (and possible a GROUP BY).


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
peter2501
peter2501
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 63
Thanks for this reply.

The current_timestamp is from SQL, it work fine.
And the query itself is part of a scripts, so the rows are already calculate.

But anyway, I will see what I can do with the leapyear thingy, sounds plausible
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27587 Visits: 13268
peter2501 (3/5/2014)

The current_timestamp is from SQL, it work fine.


Indeed it does, didn't even know it existed on SQL Server :-D


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search