473,379 Members | 1,283 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,379 software developers and data experts.

Date function spanning across time periods.

Hi.

I need the syntax in Access 2007 that will subtract one month from the current date and always get the correct prior month, i.e. in January 2012, month(date())-1 would pull December 2011 dates and in July 2012 it would pull June 2012.

Thanks for your help.
Robin
Dec 5 '11 #1

✓ answered by Scott W

This will give the date one month ago:
Expand|Select|Wrap|Line Numbers
  1. DateAdd("m",-1,Date())
"m" tells it to count by months, -1 is the interval, and the Date() is just the date function, but it can be any Date variable.

6 1858
This will give the date one month ago:
Expand|Select|Wrap|Line Numbers
  1. DateAdd("m",-1,Date())
"m" tells it to count by months, -1 is the interval, and the Date() is just the date function, but it can be any Date variable.
Dec 5 '11 #2
Rabbit
12,516 Expert Mod 8TB
Use the DateAdd function to add a negative month.
Expand|Select|Wrap|Line Numbers
  1. DateAdd("m", -1, someDateField)
Dec 5 '11 #3
sierra7
446 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. DateAdd("m", -1, Date)
S7
Dec 5 '11 #4
NeoPa
32,556 Expert Mod 16PB
Three good answers. I can also confirm that this handles difficult months correctly too.

For instance, using a value for 31st March returns the last day of February (as illustrated below) :

Expand|Select|Wrap|Line Numbers
  1. ?DateAdd("m",-1,#31/3/2011#)
  2. 28/02/2011
If I may be allowed to make a suggestion, Post #2, being the first posted and answering pretty fully as well, might be a good selection for Best Answer (With no disrespect to either of the other posts which were equally correct).
Dec 6 '11 #5
Thanks for all of your quick responses. I belive I need to use this funcgtion instead of the simple month(date()) -1 in my reports that will run every month for multiple years, is that right?

Thanks again.
Robin
Dec 6 '11 #6
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. Month(Date()) - 1
This won't work very well for January.

Only you know exactly what you need. Certainly what you say sounds sensible but we're not in a good position to cofirm as we don't know what your requirements are.
Dec 6 '11 #7

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

Similar topics

4
by: Funnyweb | last post by:
I have just notices that the date() function is not returning the correct date/time on my "server". I am running apache2 on my winxp pro laptop. My system clock is set to the correct date,...
1
by: Graeme Longman | last post by:
Hi everyone, I was wondering if anyone has written some Python code which uses a start date and end date and a given interval (day, month or year) and outputs all the time periods for that range...
4
by: Matt | last post by:
Hello. I have an Informix SQL statement that I need to run in MS SQL Server. When I try to execute it I get the following error message from Query Analyzer: Server: Msg 195, Level 15, State 10,...
8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
5
by: Dennis M. Marks | last post by:
After reading section 15.9.1.1 the ECMAScript Language Specifications I see that the date range for the Date function is +/- 100,000,000 days from 01 Jan 1970. This is called an extrapolated...
4
by: Christine | last post by:
I am having the strangest problem. I use the Date function in several of my forms and modules in an Access 2000 mdb. Lately, wherever in my code (in this one mdb) I use the Date function, it...
4
by: Patrick McGuire | last post by:
I need to get the current date in vb .NET. In vba I always used the Date() function, and the help in .NET indicates that this function still exists, but I can't seem to find it. The Now()...
1
by: adnanahmed714 | last post by:
hi all i am date function in vb with SQL statment to find the record added on the current date sSQL = "select Time ,Temprature from weather where TDate=#10/10/2006#" it works fine.but...
14
by: --CELKO-- | last post by:
Can I get a little help? Given a very simple table of events, with their durations, I want to consolidate time periods for an event that (1) touch each other or (2) overlap each other. CREATE...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
1
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.