Home > Archive > Microsoft SQL Server forum > January 2006 > date + 1 ???









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author date + 1 ???
Edward

2006-01-30, 8:24 pm

Hi group,

Using Oracle, and given that $date=30/01/2006, you can construct a query as
follows:

select * from table
where date_field between to_date('$date', 'dd/mm/yyyy') and to_date('$date',
'dd/mm/yyyy')+1

What is the equivalent with MSSQL?

Thanks,

Edward


David Portas

2006-01-30, 8:24 pm

Edward wrote:

> Hi group,
>
> Using Oracle, and given that $date=30/01/2006, you can construct a query as
> follows:
>
> select * from table
> where date_field between to_date('$date', 'dd/mm/yyyy') and to_date('$date',
> 'dd/mm/yyyy')+1
>
> What is the equivalent with MSSQL?
>
> Thanks,
>
> Edward


DECLARE @date DATETIME ;
SET @date = '20060130' ;

SELECT *
FROM table
WHERE date_col >= @date
AND date_col < DATEADD(DAY,1,@date)
;

In SQL Server DATETIME / SMALLDATETIME always includes time as well as
date. The above query restricts to a 24hr daterange so adjust the
DATEADD or < accordingly if that isn't what you intended.

--
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
--

Edward

2006-01-31, 8:23 pm

thanks
"David Portas" < REMOVE_BEFORE_REPLYI
NG_dportas@acm.org> wrote in message
news:1138665436.223913.75090@f14g2000cwb.googlegroups.com...
> Edward wrote:
>
>
> DECLARE @date DATETIME ;
> SET @date = '20060130' ;
>
> SELECT *
> FROM table
> WHERE date_col >= @date
> AND date_col < DATEADD(DAY,1,@date)
;
>
> In SQL Server DATETIME / SMALLDATETIME always includes time as well as
> date. The above query restricts to a 24hr daterange so adjust the
> DATEADD or < accordingly if that isn't what you intended.
>
> --
> 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
> --
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com