473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to get past dates from previous years?

Here's my SQL so far...

Expand|Select|Wrap|Line Numbers
  1. SELECT Format(Day([Actual Date]=Day(Date())) And Month([Actual Date]=Month(Date()))) AS "Past Date"
  2. FROM [Gas Data]
  3. ORDER BY Format([Actual Date],"mm/dd/yyyy") DESC , [Gas Data].[MCF sendout] DESC , [Gas Data].[Degree Days] DESC;
What I'm trying to do is get the same past date from the last three years for a report. For instance, for today I would need 12/3/2009, 12/3/2008 and 12/3/2007. There's a field called "Actual Date" which I'm hoping I can parse down to return the day and month for my report, but so far no success...any help would be greatly appreciated!!!

Many thanks!
Neal
Dec 3 '10 #1
2 1722
Stewart Ross
2,545 Expert Mod 2GB
Hi. There are some problems with your SQL, in that you've mixed up what you are trying to select with how you want to select it.

You want to select all rows in which the [Actual Date] field matches the current day and month. Try:

Expand|Select|Wrap|Line Numbers
  1. SELECT   [Actual Date] AS [Past Date]
  2. FROM     [Gas Data]
  3. WHERE    Month([Actual Date]) = Month(Date()) 
  4. AND      Day  ([Actual Date]) = Day(Date())
  5. ORDER BY [Actual Date] DESC;
Be aware if you use FORMAT that it returns text values, and you cannot order dates formatted as text unless you return them with the year reversed: yyyy/mm/dd for example. There is, however, no need to use format for what you want to do.

-Stewart

PS if there are no rows in table [Gas Data] with [Actual Dates] matching the current day and month then the query will not return any rows at all. Depending on what you do with this query for your report you may not find it of practical use in itself.
Dec 4 '10 #2
Awesome Stewart! That did it, works perfectly now. I knew what I wanted it to do, just could bend the SQL to my will to do so. Thanks a million!

Neal
Dec 6 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James | last post by:
Please help - getting very desperate! Sun, 12 October 2003 05:39 I have PHPDEV 4.2.3 from Firepages.com.au as the upgrade to 4.3.0 did not work. I also had an abortive download from PHP.NET as...
1
by: coolcsgeek | last post by:
i took a c++ intro cs course a few years back and recently decided to major in cs after much switching back and forth between majors. it seems my school has replaced most of it's intro level cs...
3
by: Y2KYZFR1 | last post by:
need some help getting started, it is just a "little" confusing on where to actually start. I want to write a turn based board game using Twisted as the networking layer. I just need a kind of...
4
by: Dale | last post by:
Hi Everyone, I've got a form that provides a pop-up calendar for users to select dates for requesting jobs to be completed. The calendar works great, but it unfortunately allows users to select...
0
by: Jim | last post by:
I need some help getting started with a .NET web project for a commercial site. I am new to .NET and my understanding of some (but not all) of its concepts is a little sparse. I apologize for the...
15
by: plaztik8 | last post by:
Hello, Can someone please help me with a query? The table looks like this: BookedRooms =========== CustomerID RoomID BookDateID
4
by: Allan M. Bruce | last post by:
I have a small implementation of a queue which I am trying to get to compile but cant figure out why it doesnt work. I have copied the minimum compilable code below. On gcc I get temp2.c: In...
1
by: Greg Smith | last post by:
Is there a way to disable past dates for a calendar control, or individual date for that matter? Any help is greatly appreciated.
1
benchpolo
by: benchpolo | last post by:
select DATEADD(yy, DATEDIFF(yy,0,getdate()), 0) Result ------------------------------------------------------ 2008-01-01 00:00:00.000 I have the above select statement in SQL to dispay the...
1
by: Alexnb | last post by:
The trick to this one is that the html looks something like this: <td width="100%" colspan="2"> american, a href="/browse/blue" linkindex="12" set="yes">blue brick churn cottage cream " My...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.