Solved

Need SQL code to query month to date last year

Posted on 2014-10-29
4
680 Views
Last Modified: 2014-10-30
I am trying to build a query in Access 2010 to pull data from month to date last year.

Example. today being 10/29/14, I am using Between DateAdd("d",-DatePart("d",Date())+1,Date()) And Date()-1 which pulls my data for 10/1/2014 to 10/28/2014

I am trying to look a comparable sales data so I need a piece of code that pulls 10/1/2013 to 10/28/2013
0
Comment
Question by:Cole100
4 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40411906
Did you try this:

dateadd("y",-1,DateAdd("d",-DatePart("d",Date())+1,Date()) ) and dateadd("y",-1,Date()-1)
0
 
LVL 19

Accepted Solution

by:
Eric Sherman earned 250 total points
ID: 40412006
Also try this for month to date last year ...

Between DateSerial(Year(Date())-1, Month(Date()), 1) AND DateSerial(Year(Date())-1, Month(Date()), Day(Date())-1)

ET
0
 
LVL 50

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
ID: 40412634
You could use for the current year:

    Between DateSerial(Year(Date()), Month(Date()), 1) And DateAdd("d", -1,Date())

and for last year:

     Between DateSerial(Year(Date()) - 1, Month(Date()), 1) And DateAdd("yyyy", -1, DateAdd("d", -1,Date()))

etsherman's expression for the last year is valid too. A matter of taste.

/gustav
0
 

Author Closing Comment

by:Cole100
ID: 40413926
Both etsherman and gustav solution did exactly as i  needed. thank you
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question