dbTalk Databases Forums  

datetime calculation

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss datetime calculation in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
seeker53
 
Posts: n/a

Default datetime calculation - 02-04-2005 , 10:27 AM






I have a datetime field in a SQL SERVER and I need to know clients that are
scheduled for the next day when reading the info on the current day. I have
tried

[tblevent].[begin_datetime] = dateadd(d,1,getdate())

within the where clause and this does not return any records. I know that
the records exist because when I run [tblevent].[begin_datetime] = '2/5/05'
many records return. I have also tried

[tblevent].[begin_datetime] = getdate() + 1

which also returns no records. How is the best way to solve this problem.

Reply With Quote
  #2  
Old   
Sue Hoegemeier
 
Posts: n/a

Default Re: datetime calculation - 02-04-2005 , 10:53 AM






It's hard to say for sure without knowing how the data is
stored but I would guess it could have something to do with
the time portion of your datetime data.
Try using the following and see if it works:
[tblevent].[begin_datetime] =
DateAdd(dd, 1, convert(varchar(10), GetDate(), 101))

-Sue

On Fri, 4 Feb 2005 08:27:09 -0800, "seeker53"
<seeker53 (AT) discussions (DOT) microsoft.com> wrote:

Quote:
I have a datetime field in a SQL SERVER and I need to know clients that are
scheduled for the next day when reading the info on the current day. I have
tried

[tblevent].[begin_datetime] = dateadd(d,1,getdate())

within the where clause and this does not return any records. I know that
the records exist because when I run [tblevent].[begin_datetime] = '2/5/05'
many records return. I have also tried

[tblevent].[begin_datetime] = getdate() + 1

which also returns no records. How is the best way to solve this problem.


Reply With Quote
  #3  
Old   
seeker53
 
Posts: n/a

Default Re: datetime calculation - 02-04-2005 , 02:25 PM



You are very correct it does have to do with the time part of the field but
your suggestion did not pull data either. Any other directions?

"Sue Hoegemeier" wrote:

Quote:
It's hard to say for sure without knowing how the data is
stored but I would guess it could have something to do with
the time portion of your datetime data.
Try using the following and see if it works:
[tblevent].[begin_datetime] =
DateAdd(dd, 1, convert(varchar(10), GetDate(), 101))

-Sue

On Fri, 4 Feb 2005 08:27:09 -0800, "seeker53"
seeker53 (AT) discussions (DOT) microsoft.com> wrote:

I have a datetime field in a SQL SERVER and I need to know clients that are
scheduled for the next day when reading the info on the current day. I have
tried

[tblevent].[begin_datetime] = dateadd(d,1,getdate())

within the where clause and this does not return any records. I know that
the records exist because when I run [tblevent].[begin_datetime] = '2/5/05'
many records return. I have also tried

[tblevent].[begin_datetime] = getdate() + 1

which also returns no records. How is the best way to solve this problem.



Reply With Quote
  #4  
Old   
p
 
Posts: n/a

Default RE: datetime calculation - 02-04-2005 , 02:39 PM



Used Northwind DB as an example:

Declare @OrderDate datetime

Set @OrderDate = '7/4/1996'

Select p.ProductName, o.OrderDate
From Products p
Inner Join [Order Details] od On p.ProductID = od.ProductID
Inner Join Orders o On od.OrderID = o.OrderID
--Where o.OrderDate = '7/4/1996'
Where o.OrderDate = DateAdd(dd, 1, @OrderDate)





"seeker53" wrote:

Quote:
I have a datetime field in a SQL SERVER and I need to know clients that are
scheduled for the next day when reading the info on the current day. I have
tried

[tblevent].[begin_datetime] = dateadd(d,1,getdate())

within the where clause and this does not return any records. I know that
the records exist because when I run [tblevent].[begin_datetime] = '2/5/05'
many records return. I have also tried

[tblevent].[begin_datetime] = getdate() + 1

which also returns no records. How is the best way to solve this problem.

Reply With Quote
  #5  
Old   
Sue Hoegemeier
 
Posts: n/a

Default Re: datetime calculation - 02-04-2005 , 03:33 PM



Well... I'm still needing to guess at what your data looks
like. It helps immensely when you can provide sample data
and post the DDL for the table. Try this then:
select *
from tblevent
where begin_datetime >= DateAdd(dd, 1, convert(varchar(10),
GetDate(), 101))
and begin_datetime < DateAdd(dd, 2, convert(varchar(10),
GetDate(), 101))

That would just pull the dates >= 2005-02-05 00:00:00.000
and less than 2005-02-06 00:00:00.000 so the time portion
doesn't matter. But that doesn't make sense as you said you
used
[tblevent].[begin_datetime] = '2/5/05'
and it pulled the records. Using '2/5/2005' would pull up
the data where the datetime values are 2005-02-05
00:00:00.000. And in that case, using
DateAdd(dd, 1, convert(varchar(10), GetDate(), 101))
should work.

So there is something else involved and I have no idea
without see the SQL you are using, sample data and DDL.
The only other thing I could guess is that begin_datetime
really isn't a datetime column, maybe a varchar?

-Sue

On Fri, 4 Feb 2005 12:25:05 -0800, "seeker53"
<seeker53 (AT) discussions (DOT) microsoft.com> wrote:

Quote:
You are very correct it does have to do with the time part of the field but
your suggestion did not pull data either. Any other directions?

"Sue Hoegemeier" wrote:

It's hard to say for sure without knowing how the data is
stored but I would guess it could have something to do with
the time portion of your datetime data.
Try using the following and see if it works:
[tblevent].[begin_datetime] =
DateAdd(dd, 1, convert(varchar(10), GetDate(), 101))

-Sue

On Fri, 4 Feb 2005 08:27:09 -0800, "seeker53"
seeker53 (AT) discussions (DOT) microsoft.com> wrote:

I have a datetime field in a SQL SERVER and I need to know clients that are
scheduled for the next day when reading the info on the current day. I have
tried

[tblevent].[begin_datetime] = dateadd(d,1,getdate())

within the where clause and this does not return any records. I know that
the records exist because when I run [tblevent].[begin_datetime] = '2/5/05'
many records return. I have also tried

[tblevent].[begin_datetime] = getdate() + 1

which also returns no records. How is the best way to solve this problem.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.