Solved

DateAdd Function ???

Posted on 2006-06-21
8
458 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
Back Up Your Microsoft Windows Server®

Back up 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 4

Author Comment

by:Carl2002
ID: 16949845
This works to find the prior month but how would it then find 6 months ago ?
0
 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 7 35
Access Crosstab Query with Multiple Values 4 32
Access subform not displaying on tab in naviation form 5 30
MS Access from Delphi 31 32
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.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

810 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