Sunday, February 12, 2012

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

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.
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
<almurph@.altavista.com> wrote in message
news:36124fcf-6486-43cc-8297-90972b9d9817@.h11g2000prf.googlegroups.com...
> 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.
|||On Mar 20, 3:55Xpm, "Aaron Bertrand [SQL Server MVP]"
<ten...@.dnartreb.noraa> wrote:
> Use the DATEADD function. XImplicit 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? XWhat if I did
> the same, and expected seconds, and my co-worker expects months? XSQL Server
> can't be psychic...
> A
> <almu...@.altavista.com> wrote in message
> news:36124fcf-6486-43cc-8297-90972b9d9817@.h11g2000prf.googlegroups.com...
>
>
>
>
> - Show quoted text -
Aaron,
Thank you very much.
Al.

No comments:

Post a Comment