Home > Archive > MS SQL Server MSEQ > February 2006 > Date Selection









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

2006-02-06, 9:23 am

I thought this was simple but...
I have a table with a transdate of data type datetime and I want to select
all transactions either for today or for getdate() minus some value. Looks
to me like the time portion is getting in the way of "where transdate =
(getdate() - 3)". How do I deal with just the date portions of these fields?
Thanks
--
Stan Gosselin
Sreejith G

2006-02-06, 11:23 am

Hi,

Use DATEADD function...

SELECT DATEADD(hh, -3, getdate())

Thanks,
Sree


"Stan" wrote:

> I thought this was simple but...
> I have a table with a transdate of data type datetime and I want to select
> all transactions either for today or for getdate() minus some value. Looks
> to me like the time portion is getting in the way of "where transdate =
> (getdate() - 3)". How do I deal with just the date portions of these fields?
> Thanks
> --
> Stan Gosselin

Stan

2006-02-06, 8:25 pm

Thanks for the response but this still does not work. I know how to get the
system date adjusted to meet my criteria by either using DATADD or just
getdate() - some number. I have to find a way to compare JUST the date
portion to JUST the date portion of the transaction date stored in the table.
--
Stan Gosselin


"Sreejith G" wrote:
[color=darkred]
> Hi,
>
> Use DATEADD function...
>
> SELECT DATEADD(hh, -3, getdate())
>
> Thanks,
> Sree
>
>
> "Stan" wrote:
>
Hugo Kornelis

2006-02-06, 8:25 pm

On Mon, 6 Feb 2006 06:52:43 -0800, Stan wrote:

>I thought this was simple but...
>I have a table with a transdate of data type datetime and I want to select
>all transactions either for today or for getdate() minus some value. Looks
>to me like the time portion is getting in the way of "where transdate =
>(getdate() - 3)". How do I deal with just the date portions of these fields?
>Thanks


Hi Stan,

To remove the time portion from a datetime column (or variable), use

SELECT DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP), 0)


--
Hugo Kornelis, SQL Server MVP
Stan

2006-02-08, 8:24 pm

Hugo,
This does the trick! Thanks so much for the response to this and the other
post I made.
Have a good day and thanks again for the help.
--
Stan Gosselin


"Hugo Kornelis" wrote:

> On Mon, 6 Feb 2006 06:52:43 -0800, Stan wrote:
>
>
> Hi Stan,
>
> To remove the time portion from a datetime column (or variable), use
>
> SELECT DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP), 0)
>
>
> --
> Hugo Kornelis, SQL Server MVP
>

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