PC Review


Reply
Thread Tools Rate Thread

Convert SQL Code to Use in Access Query for Dates

 
 
Leanne
Guest
Posts: n/a
 
      15th Apr 2010
I would like to use the following code to run on any day of current week and
return data for the previous week, Sun-Sat.
I found the SQL code but it doesn't work in Access. Is there any way to
tweak it so it will work and what would need to be changed?
where
-- Greater than or equal Sunday of last week
saledate >= dateadd(dd,((datediff(dd,-53684,getdate())-7)/7)*7,-53684) and
-- Less than Sunday of this week
saledate < dateadd(dd,(datediff(dd,-53684,getdate())/7)*7,-53684)

Thanks for any assistance offered.
LMR
 
Reply With Quote
 
 
 
 
Roger Carlson
Guest
Posts: n/a
 
      15th Apr 2010
Try these:
saledate >= dateadd("d",((datediff("d",-53684,date())-7)/7)*7,-53684)
saledate < dateadd("d",(datediff("d",-53684,date())/7)*7,-53684)

I'm only speaking for the sytax to use in Access. I haven't evaluated the
actual function.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/...UBED1=ACCESS-L



"Leanne" <(E-Mail Removed)> wrote in message
news:95E272A3-F2A2-44C6-A735-(E-Mail Removed)...
>I would like to use the following code to run on any day of current week
>and
> return data for the previous week, Sun-Sat.
> I found the SQL code but it doesn't work in Access. Is there any way to
> tweak it so it will work and what would need to be changed?
> where
> -- Greater than or equal Sunday of last week
> saledate >= dateadd(dd,((datediff(dd,-53684,getdate())-7)/7)*7,-53684)
> and
> -- Less than Sunday of this week
> saledate < dateadd(dd,(datediff(dd,-53684,getdate())/7)*7,-53684)
>
> Thanks for any assistance offered.
> LMR



 
Reply With Quote
 
david
Guest
Posts: n/a
 
      20th Apr 2010

"Leanne" <(E-Mail Removed)> wrote in message
news:95E272A3-F2A2-44C6-A735-(E-Mail Removed)...
>I would like to use the following code to run on any day of current week
>and
> return data for the previous week, Sun-Sat.
> I found the SQL code but it doesn't work in Access. Is there any way to
> tweak it so it will work and what would need to be changed?
> where
> -- Greater than or equal Sunday of last week
> saledate >= dateadd(dd,((datediff(dd,-53684,getdate())-7)/7)*7,-53684)
> and
> -- Less than Sunday of this week
> saledate < dateadd(dd,(datediff(dd,-53684,getdate())/7)*7,-53684)
>
> Thanks for any assistance offered.
> LMR


Here is an alternative:

Previous Saturday:
date()-weekday(date())

Sunday before that:
date()-weekday(date()) - 6

saledate >= date()-weekday(date()) - 6
and
saledate <= date()-weekday(date())

Note, this form always gives you last week, not this week. If you run it on
a Saturday, it gives you the previous Saturday.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel code convert to Access code - Concat & eliminate duplicates italia Microsoft Access Queries 1 12th Sep 2006 07:22 PM
Excel code convert to Access code - Concat & eliminate duplicates italia Microsoft Access 2 12th Sep 2006 06:13 PM
Excel code convert to Access code - Concat & eliminate duplicates italia Microsoft Access Macros 0 12th Sep 2006 05:04 PM
convert american dates from a query Mika Microsoft Excel Programming 2 2nd Nov 2005 09:37 AM
convert american dates from a query Mika Microsoft Excel Programming 5 1st Nov 2005 01:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:15 AM.