Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Help with Current DATE in Query

 
   Database Forums (Home) -> MSEQ RSS
Next:  ReOrdering Tasks in Execute Window  
Author Message
SQL Brad

External


Since: Feb 11, 2007
Posts: 7



(Msg. 1) Posted: Mon Sep 10, 2007 6:16 am
Post subject: Help with Current DATE in Query
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

Hello, I have a table that lists my bank transactions. I have a uniqueid in
the first field and several other fields....one of which is DATE.... now, I
want to run a query where my view is based upon the DATE. however I want to
only show transactions that are the same date as the system date (this is to
see how much work my employees have done). Please see my example below, this
code works....

SELECT transid, [date], description, amt, taxamt
FROM dbo.taxtransactions
WHERE ([date] = '9/9/2007')

However, where it has 9/9/2007, I want it to be TODAYS Date

Thanks for your help in advance!

 >> Stay informed about: Help with Current DATE in Query 
Back to top
Login to vote
Russell Fields

External


Since: Feb 21, 2007
Posts: 457



(Msg. 2) Posted: Mon Sep 10, 2007 1:15 pm
Post subject: Re: Help with Current DATE in Query [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

SQL Brad,

There are several ways to get the date only, without time included. This is
one of the best performing since it uses math instead of character string
conversions:

DATEADD(DD,DATEDIFF(DD,'1/1/1753',GetDate()),'1/1/1753') -- Any origin
date will do

Assuming that your DATE columns only have date set (and time set to
00:00:00.000) then this will work for you. If your transactions have date
and time, then:

WHERE DATEADD(DD,DATEDIFF(DD,'1/1/1753',MyDateColumn,'1/1/1753')
= DATEADD(DD,DATEDIFF(DD,'1/1/1753',GetDate()),'1/1/1753')

RLF

"SQL Brad" wrote in message

> Hello, I have a table that lists my bank transactions. I have a uniqueid
> in
> the first field and several other fields....one of which is DATE.... now,
> I
> want to run a query where my view is based upon the DATE. however I want
> to
> only show transactions that are the same date as the system date (this is
> to
> see how much work my employees have done). Please see my example below,
> this
> code works....
>
> SELECT transid, [date], description, amt, taxamt
> FROM dbo.taxtransactions
> WHERE ([date] = '9/9/2007')
>
> However, where it has 9/9/2007, I want it to be TODAYS Date
>
> Thanks for your help in advance!

 >> Stay informed about: Help with Current DATE in Query 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
SQL Minus 7 days from current date - How would I subtract 7 days from the current date? I can't seem to get the syntax correct? Thank you, Rachel

Date Query - I'm using sql 2000 and Access 2003. I trying to query on a date field. I need to display any records from the current date and greater then. What criteria do I use to display these records? Thanks, Paul Scott

Date Query - I need to query between todays date +14. Any suggestions on code. Thanks.

Update 'Date': Set Day(Date) to a Certain Number - Hi, I am trying to use an update command to set the day of a date to a certain number. For example, if the date is 1/4/06, I might want to set day(date) to '7'. So it turns into 1/7/06. I wasn't sure if there was a way to do this and I keep getting....

Finding the Shift for current hour - I have a table which stores the shift timing like this: ShiftId StartTime EndTime WeekDay Shift 1 6:00:00 AM 6:00:00 PM 7 Shift A 2 6:00:00 PM 6:00:00 AM 7 Shift B 4 6:00:00 AM 6:00:00 PM 112 Shift C 8 6:00:00 AM 6:00:00 PM 112 Shift D....
   Database Forums (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]