Solved

DateAdd Function ???

Posted on 2006-06-21
8
456 Views
Last Modified: 2008-02-26
I have a date in the format yyyymm and I want to be able to take 1 month off.

IE: 200606 would become 200605 I could just use [month]-1 but that would only work for 11 months of the year as 200601 would become 200600 and I want it to be 200512.

I think I need the dateadd function but cant for the life of me figure it out.

Carl.
0
Comment
Question by:Carl2002
  • 3
  • 3
  • 2
8 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 16949736
Hi Carl2002,

If you are storing the date in  a datetime field then you can use Dateadd() to subtract 1 month.


Pete
0
 
LVL 4

Author Comment

by:Carl2002
ID: 16949748
The field is a result of a query the query is simply Format(now(),"yyyymm"). Will this be a string ?
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 16949825
Format(DateSerial(Left([Field], 4), Right([Field], 2), 0), "yyyymm")
0
 
LVL 4

Author Comment

by:Carl2002
ID: 16949845
This works to find the prior month but how would it then find 6 months ago ?
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 77

Expert Comment

by:peter57r
ID: 16949869
Carl2002,
You said you wanted to take 1 month off; where does 6 months come into it?

Pete
0
 
LVL 4

Author Comment

by:Carl2002
ID: 16949884
OK sorry guys think my initial question didn't explain it all. I do want to take 1 month off, but there will be times I want to take more than 1 month off. Is this possible?
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 16949916
Another way to take 1 Month off...
Format(DateSerial(Left([Field], 4), Right([Field], 2)-1,1), "yyyymm")

To Take 6 months off...
Format(DateSerial(Left([Field], 4), Right([Field], 2)-6, 1), "yyyymm")

To Add 6 Months...
Format(DateSerial(Left([Field], 4), Right([Field], 2)+6, 1), "yyyymm")
0
 
LVL 77

Accepted Solution

by:
peter57r earned 55 total points
ID: 16949933
format (dateadd("m",-6, Now()), "yyyymm")

Set the -6 to whatever you want.

Pete
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HasData 9 37
Newbie needs help printing from a form. 10 20
Search Form not Querying 2 11
ms/access vba - how to wait for a form to close 2 15
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now