473,379 Members | 1,544 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.

How to calculate the first of the month following the end of previous month?

37
I have a query that I need help in writing the expression to calculate the first of the month following the end of previous month.

Example:
Policy expiration date = between 2/1/11 and 2/28/11
Date Letter Sent = 3/1/11

This is what I have and it only returns the number 3:

Expand|Select|Wrap|Line Numbers
  1. Date Letter Sent: (DatePart("m",[General Liability Policy Expiration Date])+1)
The correct answer should be 3/1/11. Please help. What am I missing in the expression?

Your help will be greatly appreciated.

Thanks,
Yappy
Feb 9 '11 #1

✓ answered by beacon

@Rabbit...is this what you had in mind?:

Expand|Select|Wrap|Line Numbers
  1. Date Letter Sent: DateAdd("m", 1, DateSerial(Year([General Liability Policy Expiration Date]),Month([General Liability Policy Expiration Date]),1))
  2.  
I'm not sure if it works because I don't have time at the moment to test it out, but it looks like it would work on the surface.

14 2652
beacon
579 512MB
Hi Yappy,

I think you would be better off using the DateAdd function instead of DatePart. With DateAdd you can just add one day to the expiration date and it will give you the next day. Assuming that the policy always expires on the last day of the month, you'll always get the first day of the next month.

Expand|Select|Wrap|Line Numbers
  1. Date Letter Sent: DateAdd("d", 1, ",[General Liability Policy Expiration Date])
  2.  
Hope this helps and good luck,
beacon
Feb 9 '11 #2
yappy77
37
Thanks, Beacon! Unfortunately the last day of the month is not always the expiration date. Do you have another suggestion/solution?

Yappy
Feb 9 '11 #3
beacon
579 512MB
Ok, try this on for size:

Expand|Select|Wrap|Line Numbers
  1. Date Letter Sent: DateSerial(Year([General Liability Policy Expiration Date]),Month([General Liability Policy Expiration Date])+1,1)
  2.  
Feb 9 '11 #4
Rabbit
12,516 Expert Mod 8TB
Beacon, won't that fail on december? Or does DateSerial know to increment the year?
Feb 9 '11 #5
beacon
579 512MB
@Rabbit...that was supposed to be a fun surprise for Yappy. =)
Feb 9 '11 #6
yappy77
37
So, what is the answer? Will it fail on December? And, if so, how can it be fixed?
Feb 10 '11 #7
beacon
579 512MB
It won't fail on December, per se, but it won't increment the year to the next year. If you have an expiration date of 12/10/2011, the expression will return a result of 01/01/2011 instead of 01/01/2012

You'll need to add a conditional statement that tests the current month to determine whether or not it's December. If it is December (the True part of the statement), then you'll add one to the year. If it isn't December (the False part of the statement), then you'll use what I provided above.
Feb 10 '11 #8
Rabbit
12,516 Expert Mod 8TB
Or you could DateSerial to the first of the current month and then DateAdd a month.
Feb 10 '11 #9
beacon
579 512MB
@Rabbit...is this what you had in mind?:

Expand|Select|Wrap|Line Numbers
  1. Date Letter Sent: DateAdd("m", 1, DateSerial(Year([General Liability Policy Expiration Date]),Month([General Liability Policy Expiration Date]),1))
  2.  
I'm not sure if it works because I don't have time at the moment to test it out, but it looks like it would work on the surface.
Feb 10 '11 #10
Rabbit
12,516 Expert Mod 8TB
That's pretty much what I was thinking.
Feb 10 '11 #11
yappy77
37
This works perfectly. Thank you so much for your help!
Feb 11 '11 #12
yappy77
37
Rabbit,
Your idea worked perfectly. Thank you for your help!
Feb 11 '11 #13
gershwyn
122 100+
Actually, the DateSerial function will carry over to the next year if the you supply a month of 13.
Expand|Select|Wrap|Line Numbers
  1. Print DateSerial(2010, 13, 10)
gives:
Expand|Select|Wrap|Line Numbers
  1. 1/10/2011
I'm sure date settings could come into it, but it works on my machine. Anyway, the accepted answer works just as well and as far as I know are equivalent, but I just wanted to point that out.
Feb 11 '11 #14
beacon
579 512MB
They are equivalent...the only difference being that you identify the literal 13th month and the other is adjusted based on the value in the field.
Feb 12 '11 #15

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

Similar topics

2
by: Terry | last post by:
I have a database that I would like to query for a specific date range. I want to create a report based on this query that will pull any records from the last 7 days. Is this possible? Can...
0
by: Chucky | last post by:
I have been going crazy slowly all week. When I step through my code I get Run Time Error 3075, Syntax error, Missing Operator in Query Expression. I think that I have narrowed the error down to...
4
by: Cantell | last post by:
Hi everyone I have created a small db, in access 2000, on my own test machines it works excellent, however, upon transferring it to my colleague, I expierience a strange error code Function is...
3
by: Sheldon | last post by:
I have the following query expression - Like Format((!!)) & "/*/" & (! !) which would translate to e.g. 04/*/2007 if someone is running a report for last month. The above expression is part of a...
0
by: blackjackkiller | last post by:
Hi Need help in automating the report.Let me give the explanation what i need that might help u in understanding it. 1 need excel macro to run a query to pull data from sql server for specific...
5
by: Just_a_fan | last post by:
I tried to put an "on error" statement in a routine and got the message that I cannot user "on error" and a lamda or query expression in the same routine. Help does not list anything useful for...
5
by: OzNet | last post by:
Can someone tell me what I am doing wrong here please? I have a form with two unbound text boxes formatted to short date and an OK button. My button code is as follows: Private Sub...
3
by: shawnmiller77 | last post by:
Need Help ASAP! History: Installed new SBS 2003 server on Monday. Migrated IIS, website and current Access database over to new server. I did not develop the website or Access database. Former...
2
by: Lieven | last post by:
The problem is fairly complex. I have a table where I can add records. These records have several parts. Each record consists of ID, Date, Train Number and many more. I have a form where I can...
7
by: colintis | last post by:
I'm fixing a query that takes date filter on specific date (e.g. 10/13/2010). The date field in the table source also contains time along with the date. (E.g. 13/10/2010 6:26:45 AM) On the where...
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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.