You are here: Re: Get all records from Last Two Days? « MsSQL Server « IT news, forums, messages
Re: Get all records from Last Two Days?

Posted by Erland Sommarskog on 10/02/18 11:45

John (nothanks@nope.com) writes:
> I use the following to get records from the last two days in MySql:
> where date_entered <= curdate() and date_entered >=
> DATE_SUB(curdate(),INTERVAL 2 day)
>
> I'm looking to do the same in MS-Sql server but I'm just not getting it.
> I've got this so far which does not work:
> where hit_date <= GETDATE() and hit_date >= DATE_SUB(GETDATE(),INTERVAL
2
> day)
>
> then I tried this:
> WHERE hit_date >= DATEDIFF(GETDATE(), (GETDATE()-2)>
>
> Essentially, I need all records from the last two days.

Since you appear to be trying out syntax at random, I must ask: did
you ever consider to consult Books Online?



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация