Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Date and Time in MS SQL

Posted on 2006-06-28
5
304 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

829 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