Solved

Date and Time in MS SQL

Posted on 2006-06-28
5
269 Views
Last Modified: 2008-02-26
Hello,

I'm running this:

select ..... where Create > CONVERT(DATETIME, CONVERT(INT, GETDATE() -1)))

Create = Field Name

I'm getting June 28 and June 27... but I should get only June 27

I even tried this: CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, GETDATE()-1 ))
and
CONVERT(DATETIME, CONVERT(INT, GETDATE() -1))

but I'm not getting only for June 27....    -1 should take me a day back..no? but it doesn't... can anyone help me with this please

Thanks


0
Comment
Question by:ezzadin
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:skacore
ID: 17004129
Hello,
  You may want to try

SELECT .... WHERE create > DATEADD(d, -1, GETDATE())

If you just want stuff from a day ago, it's a little cleaner.
0
 

Author Comment

by:ezzadin
ID: 17004164
still the same.... I'm getting some of June 27 and some of June 28

the first record start    2006-06-27 17:50:08.000

I have some records that are 2006-06-27 00:00:00.000 ... i should get those as well and not get June 28

Please help

Thanks

0
 
LVL 1

Accepted Solution

by:
skacore earned 250 total points
ID: 17004265
Ah, now I see, try this:

SELECT ....  create >= DATEADD(dd, -1, DATEDIFF(dd, 0, GETDATE())) and create < DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
0
 
LVL 2

Assisted Solution

by:MyersA
MyersA earned 250 total points
ID: 17004309
Hi ezzadin,

When I compare dates, I usually get rid of the time and I only use the date part. You can try this:
SELECT .... WHERE
create >= convert(DateTime,convert(varchar(11),getdate()-1)) and       
create < convert(DateTime,convert(varchar(11),getdate()))


0
 

Author Comment

by:ezzadin
ID: 17004555
Thanks guys
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now