Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / March 2008

Tip: Looking for answers? Try searching our database.

Adding an int to a datetime type as minutes -- pleasse help!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
almurph@altavista.com - 20 Mar 2008 16:49 GMT
Hi,

    I'm trying to add an int type to a datetime type to produce a
datatime type that interprets the int as *minutes*, for example:

2008-03-20 15:36:09.920 + 10 = 2008-03-20 15:46:09.920

    Problem is though - I'm stuck. Whenever I try to do this SQL Server
2005 interprets the "int" as days and I get the wrong answer. Can
ayone help me please? Any comments/suggestions/code-samples much, much
appreciated.

Thank,
Al.
Aaron Bertrand [SQL Server MVP] - 20 Mar 2008 16:55 GMT
Use the DATEADD function.  Implicit DATETIME math is always in number of
days.

SELECT DATEADD(MINUTE, 10, '2008-03-20 15:36:09.920');

While the default is not entirely intuitive, why would you assume that SQL
Server will know that when you typed "10" you meant minutes?  What if I did
the same, and expected seconds, and my co-worker expects months?  SQL Server
can't be psychic...

A

> Hi,
>
[quoted text clipped - 10 lines]
> Thank,
> Al.
almurph@altavista.com - 20 Mar 2008 17:06 GMT
> Use the DATEADD function.  Implicit DATETIME math is always in number of
> days.
[quoted text clipped - 28 lines]
>
> - Show quoted text -

Aaron,

  Thank you very much.

Al.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.