473,609 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding to a date

How do I add to a date? I thought the following code would work but it
doesn't like it. I'm trying to add 6 months (182 days) onto a date.

Option Explicit

Private Sub Form_Load()
Dim Answer As Integer
Dim GivenDate As Date
GivenDate = "2/1/2004"
Answer = GivenDate + 182
Label1.Caption = Answer
End Sub
Jul 17 '05 #1
9 36183
> How do I add to a date? I thought the following code would work but it
doesn't like it. I'm trying to add 6 months (182 days) onto a date.

Option Explicit

Private Sub Form_Load()
Dim Answer As Integer
Dim GivenDate As Date
GivenDate = "2/1/2004"
Answer = GivenDate + 182
Label1.Caption = Answer
End Sub


Look up the DateAdd function in your help files. Also, while assigning
literal date values with a String, it is better to do it using # signs
instead.

GivenDate = #2/1/2004#

Rick - MVP
Jul 17 '05 #2

"Rick Rothstein" <ri************ @NOSPAMcomcast. net> wrote in message
news:Mu******** ************@co mcast.com...
How do I add to a date? I thought the following code would work but it
doesn't like it. I'm trying to add 6 months (182 days) onto a date.

Option Explicit

Private Sub Form_Load()
Dim Answer As Integer
Dim GivenDate As Date
GivenDate = "2/1/2004"
Answer = GivenDate + 182
Label1.Caption = Answer
End Sub


Look up the DateAdd function in your help files. Also, while assigning
literal date values with a String, it is better to do it using # signs
instead.

GivenDate = #2/1/2004#

Rick - MVP


Thanks Rick. Only problem is the college dont have a license to give out the
MSDN library, so the help files on my copy of VB6 dont work. Can someone
please help? I want to be able to add 182 days OR 6 months. Thanks
Jul 17 '05 #3
On Sat, 6 Mar 2004 10:01:29 -0000, "Roy Riddex"
<ro************ **@blueyonder.c o.uk> wrote:

<snip>

Thanks Rick. Only problem is the college dont have a license to give out the
MSDN library, so the help files on my copy of VB6 dont work.
That is disgraceful
Can someone
please help? I want to be able to add 182 days OR 6 months. Thanks


NewDate = DateAdd(interva l, number, OldDate)

The 'Interval' strings are :-

yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second

eg: 6 months
NewDate = DateAdd( "m", 6, OldDate)

eg: 182 days
NewDate = DateAdd( "d", 182, OldDate)
Jul 17 '05 #4
> <snip>

Thanks Rick. Only problem is the college dont have a license to give out theMSDN library, so the help files on my copy of VB6 dont work.


That is disgraceful
Can someone
please help? I want to be able to add 182 days OR 6 months. Thanks


NewDate = DateAdd(interva l, number, OldDate)

The 'Interval' strings are :-

yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second

eg: 6 months
NewDate = DateAdd( "m", 6, OldDate)

eg: 182 days
NewDate = DateAdd( "d", 182, OldDate)


First, I'd like to not that adding 182 days (as you originally proposed)
will not always cover an exact 6-month period of time... the starting date
and the varying number of days for the subsequent months will affect it. Use
the "m" interval argument coupled with the "6" for the exact answer no
matter what your OldDate is.

Now, yes, I agree with JFrench's statement... it is disgraceful that your
college didn't acquire the Help files for its students... how short-sighted
can you get? If you go to this link...

http://msdn.microsoft.com/library/

it will take you to the online Microsoft Help files. They are not as
convenient to use as a local copy of the MSDN would be, but they'll do.
Follow this "tree" down to the VB6 section covering the Language and Control
references...

-Visual Tools and Languages
-Visual Studio 6.0
-Visual Basic 6.0
-Product Documentation
-Reference
-Language Reference
-Controls Reference

under which you will find the syntax for the things you will encounter in
VB6.

Rick - MVP
Jul 17 '05 #5

"J French" <er*****@nowher e.com> wrote in message
news:40******** ********@news.b tclick.com...
On Sat, 6 Mar 2004 10:01:29 -0000, "Roy Riddex"
<ro************ **@blueyonder.c o.uk> wrote:

<snip>

Thanks Rick. Only problem is the college dont have a license to give out theMSDN library, so the help files on my copy of VB6 dont work.


That is disgraceful


If I am not mistaken, at work when we got MSDN library for a while
(circa 2000), they changed the license to say more or less "one copy is
all you need for all the people where you work to use this". So I think
your college can legally allow multiple users to install their one copy
(hopefully they have one copy).
Jul 17 '05 #6
Thanks for all your help. Unfortunately the MSDN library problem has been
ongoing since I started at college last August. Not even the in-house
college machines have it installed so there is no chance of me aquiring a
copy for home. However, as the course gets steadily more difficult I think I
may need to 'aquire' a copy from somewhere else.

Roy
Jul 17 '05 #7
Label1.Caption = Format(Answer," mm/dd/yyyy")

"Roy Riddex" <ro************ **@blueyonder.c o.uk> wrote in message
news:on******** ********@news-binary.blueyond er.co.uk...
How do I add to a date? I thought the following code would work but it
doesn't like it. I'm trying to add 6 months (182 days) onto a date.

Option Explicit

Private Sub Form_Load()
Dim Answer As Integer
Dim GivenDate As Date
GivenDate = "2/1/2004"
Answer = GivenDate + 182
Label1.Caption = Answer
End Sub

Jul 17 '05 #8
Label1.Caption = Format(Answer," mm/dd/yyyy")


Erm....did you read the OP? I had asked how to add days or months onto a
date. I didn't ask how to format a date, but thanks anyway.
Jul 17 '05 #9
> > Label1.Caption = Format(Answer," mm/dd/yyyy")

Erm....did you read the OP? I had asked how to add days or months onto a
date. I didn't ask how to format a date, but thanks anyway.


The OP asked about adding to the date. He did this by using Answer = GivenDate +
182, which is how to add to the date. To reformat it into a human-readable date,
you use Format. The only point I'd raise is to use Format$() as this converts it
into a string automatically, and saves the computer time (especially if done in
a loop).

--
QuickHare
(QuickHare "at" Hotmail "dot" com)
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2488
by: sandy | last post by:
Hello, I am trying to automate a date. When typing in the issue date I want it to automatically calculate 6 months fronm the issue date and give me the Expiration date. Following is code that I am using: <td>Visa Issued Date:</td> <td><input name="visaIssueDate" type="text" size="8" maxlength="8" value="#DateFormat(get_NamesContacts.VisaIssueDate, 'mm/dd/yy')#" onBlur="checkDate(this)"></td> <td>Expiration Date:</td>
11
14396
by: Bobbak | last post by:
Hello All, I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and ‘Stats') that each contain the list of EmployeeIDs, I want to be able to create a Module in which I could call in my VB form (by clicking and command button)that will add a column (field) to each table and label it with the current date that is specified in my form. Does anyone know how I can go about doing this? Any suggestion will be greatly appreciated.
7
8761
by: John Baker | last post by:
HI: I have a date, and am trying to do something that SHOULD be very simple -- but finding a problem. Assume the date is 01/01/03. I wish to make the date 02/01/03, and then next month 03/01/03 and so on. In other words, I want to add one to the month and reset the date. However, adding a given number of days (say 30) does not work because of the variation in the number of days in a month. Is there a simple way to increment dates by a...
3
4868
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
6
2623
by: ninrulz | last post by:
I have created a database that has over 70 queries and over 40k records. I used the OutputTo action to export the queries to Excel. I would like the functionality of adding the date (Month-YY) to each of the Excel file names as they are exported. It seems that the OutputTo action only allows for predetermined names or a prompt for each file. I do not want to type the file names 70+ times and renaming each of the ..xls files afterwards is a...
5
3470
by: GarryJones | last post by:
I have code numbers in 2 fields from a table which correspond to month and date. (Month, Code number) Field name = ml_mna 1 2 3 etc up to 12 (Data is entered without a leading zero)
2
2556
by: dympna | last post by:
Hi can anyone suggest a fix for this... as I am a novice in access. I have created a training table with the following fields Employee Name - joe Training Received - Fork lift Date Received - 20/6/07 Certificate - yes What I want to create is a renewal date for this training, there are
4
3953
tolkienarda
by: tolkienarda | last post by:
hi all I am working on a php driven database program for a literacy program, it will allow them to keep track of classes and students, the part i am strugling with is adding new classes, the add_class page looks like: <body> ADD CLASS<br> Class Title: <input type="text" value="class_title"><br> Class Name: <input type="text" value="class_name">(Must be Unique)<br> <input type="checkbox" name="children" value="children">Children's...
17
3435
by: ginajohnst | last post by:
Hi All. I'm having a problem adding days to a date. My date is in the string format dd/mm/yyyy eg. 23/08/2007 in my form field. I can't work out how to add 50 days to that date and then write it to another form field.
0
8091
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,...
0
8555
jinu1996
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...
1
8232
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,...
0
8408
tracyyun
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...
0
7024
agi2029
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...
1
6064
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.