Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date and Time in MS SQL

Posted on 2006-06-28
5
Medium Priority
?
330 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
[X]
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
  • 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 1000 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

618 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