Full disclosure, I know nothing about coding.
My company has label software that requires an expiration date for our product. Currently, we manually input this date. It is an issue because if the date is incorrect it would require us to perform a recall.
Is there a way to create a code that automatically calculates the expiration date that would be end of month in intervals of 5, 11, and 23 months?
4 3295
Recalls sound expensive.
It is not difficult to do, but how do you intend to input the information and get the output.
Sorry, you need code, so you need to create a module with this code:- -
Option Compare Database
-
Option Explicit
-
-
Function LastDayOfMonth(StartDate As Date, MonthsAway As Integer) As Date
-
'Print LastDayOfMonth(#1/2/17#, 2) January second
-
'Print LastDayOfMonth(#2 jan 2017#, 2) January second
-
'###### NOTE DATE MUST BE ENTERED AS #mm/dd/yyyy# or #dd mmm yyyy#
-
-
Dim NewDate As Date
-
-
NewDate = DateAdd("m", MonthsAway, StartDate)
-
-
LastDayOfMonth = DateSerial(Year(NewDate), Month(NewDate) + 1, 0)
-
-
End Function
-
Note the remarks that the start date must me in American format or with the month spelt out.
Phil
Thank you Phil. I perhaps should have included the need for the format to be YYYY-MM-DD. What would I need to change in order to get that format?
Is that the Input or Output format or both?
Phil
Phil's code is correct, but shows another way. - Dim baseDay As New DateTime(2000, 8, 31, 20, 30, 0)
-
Dim date1 As DateTime = baseDay.AddMonths(23)
-
Dim days As Integer = date1.DaysInMonth(date1.Year,date1.Month)
-
Dim lastDayOfDate1 = New DateTime(date1.Year, date1.Month, days)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: db |
last post by:
I am trying to build a db in Access2000 that will allow me to
calculate month end returns on investments. I am about to try VBA for
the first time, but wonder if I can do what I want by using
expressions in a query. Here's the problem...how do I make an
expression for a record that pulls another record needed to complete
the expression. IE, I am in the record for last months market value
and need to access the prior months market value...
|
by: bufbec |
last post by:
I have worked on this for hours and can't come up with a solution. Hope
someone can help me.
I have a table called TMBS_HMAUDIT_PARMS. this table contains data to
tell me how often a person is allowed to receive services for various
programs we offer. columns in this table include PROGRAM_NAME,
PROGRAM_ID, ALLOWED_PER_MONTHS. In the ALLOWED_PER_MONTHS column, a
numerical value of '9' in the 'ALLOWED PER MONTHS' column means a
person is...
|
by: tkq |
last post by:
I have a normal table with customer information
I have a DoB field and I want to have an automatic calculation that will show
the age of the customer in another field next to it called Age
Could you please help me with this
Thanx all
|
by: Aussie Rules |
last post by:
Hi,
How do I extract just the month part of a date. Say for example I wanted to
get the value of 6 (as in sixth month) from todays date.
Regards
|
by: crane.jake |
last post by:
Hi, I'm trying to find the following information from the table found
bellow.
Year_Sales - # of sales that have occurred this year
Year_Income - SUM(amount)
Month_Sales - # of sales that have occurred this month
Month_Income - SUM(amount)
Today_Sales -- # of sales that have occurred today
Today_Icome - SUM(amount)
| |
by: Paul H |
last post by:
I have a db that stores people and their birth dates. On any given day, I
need to know who has a 40th birthday one month from now. I will only be
running the query on week days but of course some peoples 40th birthdays
will fall on Saturday and Sunday, I may also be out of the office on certain
days. So I need to "cast a net" to catch all birthdays "approximately" one
month from now, but that "approximation needs to be predictable.
How...
|
by: guyborn |
last post by:
I have been trying to get data from the database from the of the previous month to the second last week of the current month.I only managed to get data from the previous month to today's date.
your help will be highly appreciated
Regards
Guyborn
|
by: John |
last post by:
Hi
How can I calculate age from a given DOB?
Thanks
Regards
|
by: RZ15 |
last post by:
Hi guys,
I'm really drawing a blank here for how to deal with fiscal months in my monthly sales/receipts reports. My issue is that calculating the months is not as simple as saying 'if the invoice date is january then sum sales' because the first period may include the end of december or even the beginning of february and not all of january.
To help me with my problem, it's probably helpful to not think of it as fiscal months but think of...
|
by: BikeToWork |
last post by:
I have been tasked with calculating the months left on a Task Order based on the Funds Remaining and the amount spent. I wrote queries that give me the TO original value, FundsRemaining, the amount spent, and the percentage spent and how many months the money was spent in but I am having trouble extrapolating how many months of funding remain at the current consumption rate.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |