Showing posts with label wasadded. Show all posts
Showing posts with label wasadded. Show all posts

Sunday, March 11, 2012

Compare Dates

Hi,
I have a datetime SQL column wich contains a timestamp from when the row was
added using the GetDate() function. I would like to retrive rows based on a
comparsion of the date part of this value (discard the hours,minutes etc).
The datetime variable I am passing in to my stored procedure is a DateTime
object from VB .Net and only contains Year,Month,Day. How do I produce a
select statement that ignores the time part of the sql datetime value ?
i.e.
SELECT * From MyColumn WHERE DateAdded=@.InDate
Niclas"Niclas" <lindblom_niclas@.hotmail.com> wrote in message
news:Oi2u5M%23PGHA.3432@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I have a datetime SQL column wich contains a timestamp from when the row
> was added using the GetDate() function. I would like to retrive rows based
> on a comparsion of the date part of this value (discard the hours,minutes
> etc).
> The datetime variable I am passing in to my stored procedure is a DateTime
> object from VB .Net and only contains Year,Month,Day. How do I produce a
> select statement that ignores the time part of the sql datetime value ?
> i.e.
> SELECT * From MyColumn WHERE DateAdded=@.InDate
> Niclas
>
SELECT *
FROM your_table
WHERE dateadded >= @.indate
AND dateadded < DATEADD(DAY,1,@.indate);
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Hi there,
I always use the ISO representation of the date:
CONVERT(VARCHAR(10),GETDATE(),112)
HTH, Jens Suessmeyer.|||To remove the time part of the date:
select convert(datetime,convert(char(8),getdate
(),112))
2006-03-04 00:00:00.000
Roy Harvey
Beacon Falls, CT
On Sat, 4 Mar 2006 23:21:14 -0000, "Niclas"
<lindblom_niclas@.hotmail.com> wrote:

>Hi,
>I have a datetime SQL column wich contains a timestamp from when the row wa
s
>added using the GetDate() function. I would like to retrive rows based on a
>comparsion of the date part of this value (discard the hours,minutes etc).
>The datetime variable I am passing in to my stored procedure is a DateTime
>object from VB .Net and only contains Year,Month,Day. How do I produce a
>select statement that ignores the time part of the sql datetime value ?
>i.e.
>SELECT * From MyColumn WHERE DateAdded=@.InDate
>Niclas
>|||Niclas
SELECT CAST(FLOOR(CAST(GETDATE() AS FLOAT))AS DATETIME)
"Niclas" <lindblom_niclas@.hotmail.com> wrote in message
news:Oi2u5M%23PGHA.3432@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I have a datetime SQL column wich contains a timestamp from when the row
> was added using the GetDate() function. I would like to retrive rows based
> on a comparsion of the date part of this value (discard the hours,minutes
> etc).
> The datetime variable I am passing in to my stored procedure is a DateTime
> object from VB .Net and only contains Year,Month,Day. How do I produce a
> select statement that ignores the time part of the sql datetime value ?
> i.e.
> SELECT * From MyColumn WHERE DateAdded=@.InDate
> Niclas
>