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 9 36113
> 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
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:Mu********************@comcast.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
On Sat, 6 Mar 2004 10:01:29 -0000, "Roy Riddex"
<ro**************@blueyonder.co.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(interval, 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)
> <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(interval, 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
"J French" <er*****@nowhere.com> wrote in message
news:40****************@news.btclick.com... On Sat, 6 Mar 2004 10:01:29 -0000, "Roy Riddex" <ro**************@blueyonder.co.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).
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
Label1.Caption = Format(Answer,"mm/dd/yyyy")
"Roy Riddex" <ro**************@blueyonder.co.uk> wrote in message
news:on****************@news-binary.blueyonder.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
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.
> > 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) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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)
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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...
|
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,...
|
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...
|
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...
| |