how to get the number of days between two date formatted fields in vba for excel?

how to get the number of days between two date formatted fields in vba for
excel?


0
7/12/2005 12:50:10 AM
excel 39879 articles. 2 followers. Follow

1 Replies
459 Views

Similar Articles

[PageSpeed] 53

Hi Daniel,
If they are Excel dates they represent the days and fractional days past
Dec 31, 1899 if using the 1900 date system.    So if you just have dates
they have no fractional components and you just subtract the earlier
date from the later date for the number of days.    So it doesn't really
matter if it is   Excel  or VBA   same method.

A1:   1998-11-28    B1:  2005-07-11  C1:  =B1-A1
    format c1 as number:   #,##0
    otherwise you will see:  1906-08-13

in VBA  something like either of these, no formatting required
[c1] = [b1] - [a1]
Cells(1,3).value = Cells(1,2).value - Cells(1,1).value

More information on Date and Time in (two pages are not much alike)
  http://www.mvps.org/dmcritchie/excel/datetime.htm
  http://www.cpearson.com/excel/datetime.htm
---
HTH,
David McRitchie, Microsoft MVP - Excel    [site changed  Nov. 2001]
My Excel Pages:  http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page:        http://www.mvps.org/dmcritchie/excel/search.htm

"Daniel" <softwareengineer98037@yahoo.com> wrote l...
> how to get the number of days between two date formatted fields in vba for
> excel?
>
>


0
dmcritchie (2586)
7/12/2005 1:32:59 AM
Reply:

Similar Artilces:

i get error 404 not found when trying to download
I'm trying to download nokia pc suite to windows xp to upload gallery onto the computer but get error message404 not found - how can i download this pc suite please -- Krysy Albutt Krysy Albutt wrote: > I'm trying to download nokia pc suite to windows xp to upload gallery > onto the computer but get error message404 not found - how can i > download this pc suite please Care to enlighten us how this pertains to: - 1) Microsoft 2) Publisher 3) Windows If you're having problems downloading from the *NOKIA* site where do you think you should be directing your ...

Convert European currency format to dollars
I have currency data which is stored in Euopean currency and I want to format it to dollars on a regular basis. Is there an easy way for Excel to do this?. I have tried formatting cells and replacing characters by search and replace, but this is bit hit and miss. The data is stored as 1.234,56 and I want to convert it to 1,234.56 Mark In Excel, click on Tools/Options, then the International tab. The top section is "Number handling", and you can specify what you want to use as decimal and thousands separators. Click on the Use system separators box to remove the check mark, an...

Number format issue Access 2007
Access 2007. I've created a database with a number input and I'm getting the following errors. I've formatted a field as Number Field Size: Single Format: Currency Decimal Places: 0 I'm getting the following results Input 2,065,000,000 but it's rounding it to 2,064,999,936 Input 2,682,000,000 but getting rounded to 2,681,999,872 Any ideas on the reason for this? Do I have that field formatted properly? You help is GREATLY appreciated! (B^>)-]=[ Single is a floating point type. Accuracy is only 7 or 8 significant digits. More info: ...

Q: How to automatically adapt column width with XML format?
Hi. I'm developing an application that outputs its results to an XML file (with Excel XP's DTD). The trouble is the column width, which is set at default. Is there an XML tag which allow to adapt width automatically? I thought about a VBA macro, but I noticed that VBA code isn't stored in XML Excel's files. Thanks in advance, Francesco. ...

How to get Calendar to send me reminders
I have changed my e-mail address but for some reason I cannot get Calendar to send reminders to my new address - I think I have carried out all that is necessary to effect the changover but I am not getting reminders sent. Can anyone help please? Is the Calendar Live ID based and accessible at Calendar.live.com ? -- ....winston ms-mvp mail "Dabardevon" wrote in message = news:FDC2B3B2-EDE4-41B1-BFC4-C0F9ED59CFB9@microsoft.com... I have changed my e-mail address but for some reason I cannot get = Calendar to send reminders to my new address - I think I have...

Some recipients get the attachment, some get winmail.dat
This one has me baffled. We are using Exchange 2000 and Outlook 2000 and have been for 8 months. No previous problems with attachments (.doc, .xls, .jpg). About 2 weeks ago, we started hearing from certain recipients that the attachment wasn't arriving; instead they were getting an unreadable file called winmail.dat. MS says that this is because the sender is using Rich Text to format the email. We have changed the senders to use Plain Text and still have the same problem. If the email is sent to several recipients, some will get the attachment fine, some will not. This didn'...

Calculating Fields and Manual Input
Hello, Is it possible to have a field that is both calculated or manually inputted?. For example, if field 1 and field 2 has data then calculate field 3. Can we also have the user simply enter the total amount into 3. What I have noticed is if I enter an amount directly into field 3 and field 1 and 2 do not have data the value goes back to 0 (which makes sense) but wondering if there is a way around this. Thanks! On Jul 1, 6:06 am, MDV1457 <MDV1...@discussions.microsoft.com> wrote: > Hello, > Is it possible to have a field that is both calculated or manually > inputted...

need a date look here
This is a multi-part message in MIME format --=_NextPart_2rfkindysadvnqw3nerasdf Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Get all the hots girls @ www.pearlymae.com --=_NextPart_2rfkindysadvnqw3nerasdf Content-Type: text/html Content-Transfer-Encoding: quoted-printable <html> <head> <meta name=3D"GENERATOR" content=3D"Microsoft FrontPage 6.0"> <meta name=3D"ProgId" content=3D"FrontPage.Editor.Document"> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dwindow...

Keeping Sent Items in sync across two PCs
I asked this question a few days ago in the microsoft.public.outlook.general forum but didn't get any replies, so I thought I'd try here instead... I have two computers, and both use Outlook 2000 for email. I don not use an Exchange server - email is by POP3/SMTP. Both computers collect the same email by POP3, and are set up to leave messages on the server for 30 days so nothing is missed on either PC. This works well, but the only problem is that when I send an email, it is only in the Sent Items fold of the PC that I used to send the email. Is there a way to 'copy' group...

A Crystal Beginner
I am using Crystal 9.2.4.77 and have loaded the Crystal enhancements. Now I want to do against the CRM database. What do I do? I thought I would create a data source to the CRM SQLserver, which I did, then connect to it through Crystal Reports. That works, but when I drill down on the AAA_MSCRM database to choose my tables, it shows me dbo as the only option (where did this come from??) and under that are just a few generic tables. No CRM tables. Something's not quite right. What am I missing? file - log on to aps server "KBLawson" <klawson@aetinc.com> wrote in ...

numbering multilevel list word 2007
trying to use a multilevel number list and when I hit ENTER (return) the numbering stops (the icon for numbering become un-highlighted) If this is numbering attached to headings, note that, by default, the Normal style will be applied to text when you press Enter (at the end of a heading). You can change the "Style for following paragraph" in the style definition for the relevant heading(s). -- Stefan Blom Microsoft Word MVP "dheuermann" <dheuermann@discussions.microsoft.com> wrote in message news:EEF7E0F7-76A1-4B55-98B3-981E303C7A68@microsoft.co...

formattting numbers
I am trying to format text in a textbox so it is in 3 columns (I'm using a fixed width font so it will align correctly). The 3rd column is a number. I would like it to be decimal point aligned (with possibly 1 leading zero - not 2 or 3 leading zeros). So I would like the output to be: AAAAA BBBBBBB 123.45 AAA BBBBB 0.11 AAAAA BBBBBBB 3.20 The code below aligns correctly but gives me 2 extra leading zeros. I basically want this output but have the 2 leading digits replaced with a space if no digit is present. Text1.SelText = " &quo...

How to get the CScrollBar's Handle in CTreeCtrl?
Hey,All: I thought I have a problem when I trid to get the CScrollBar's handle from my CTreeCtrl extended handle. Can anybody tell me whether I can get the handle of the CScrollBar from the CTreeCtrl? Thanks in advance! Carl :-| Carl wrote: > Hey,All: > > I thought I have a problem when I trid to get the CScrollBar's handle from > my CTreeCtrl extended handle. > Can anybody tell me whether I can get the handle of the CScrollBar from the > CTreeCtrl? > > Thanks in advance! > Carl > :-| > > Sorry, it is not that simple. The scroll bars that...

Automatic Numbering Rows
Hi all... Can't find how do to this using Excel 2003... I want to be able to have Excel automatically number rows (in the first column) that have text on them...but skip numbering rows without...and adjust the numbering if new rows get added in later. (I guess something similar to Bullets and Numbering in Word). Here's an example of what I want if I'm not making myself clear... 1. Text Here 2. Text Here 3. Text Here (Empty row...no text) 4. Text Here 5. Text Here (Empty row...no text) 6. Text Here etc.. Then...let's say...at a later date...I inserted a new row under...

wrong number in cell
In XP PRO & Excel 2002 I have a cell formated as General and unlocked. I try to enter a number { 08607100 } I hit enter and it changes to { 8607100 } no matter what I try it. This is another example of a problem in a cell I enter { 03E2 } hit enter and it changes to { 3.00E+02 }. Is there some bug in certain cells or with excel 2002 or is there some setting I am missing? Help -- Thanks MK pipco wrote: > In XP PRO & Excel 2002 I have a cell formated as General and unlocked. I > try to enter a number { 08607100 } I hit enter and it changes to { 8607100 &g...

Using current date track budget.
Hi, I am trying to update a percentage completion cell in a budget tracking spreadsheet based on the current month. Basically I have a row for each activity and a column for each month. I enter the hours completed for each activity in each month. I have a total number of hours value which will be used to calculate the %completed. So what I need is to a formula that will calculate the following: if ( this month is April) then (sum the hours from start month to april and divide by the total hours cell) else if (this month is May) then (sum the hours from start month to april and ...

Case numbering 01-26-04
I have found the auto numbering in 1.2, but it only lets me change the prefix for the cases "CAS". I need to start my numbering at 3500 instead of 1000. Is there a way to change the starting number? Thanks, Stefanie ...

file is locked does not appear in Excel if file already open by an
We have shared files on a network drive. When a file is open by one user, and a second user opens the file we want them to recieve <filename> is locked for editing message and open the file read only. This works great for some users, but we have several users that can open the file (even if someone is already in it) and they do not get the prompt and can edit the workbook. Is there a setting that would turn this off for some users and not others in excel? Hello Leslie, You could try sharing the workbook. With the Excel workbook open, choose Tools from the menu. Choose Share W...

Cannot get fast forward or fast reverse to work with WMP 11
I am running Vista Home Premium on a HP G 217-EM Notebook which comes pre-installed with Windows Media Player 11. When I play cds and try to fast forward or fast reverse by keeping the fast forward or fast reverse buttons constantly depressed nothing happens. Why is this, and can anyone come up with a solution? Many thanks This doesn't work on my system either, so it's probably just a limitation of WMP. Fast forward and fast reverse should work fine when you rip the CD's to MP3 or WMA files, and play these files instead. Regards -- Tim De Baets http://www....

default days
On excel 2003 i am using networkdays function on that the default was set to 5 days now i want to change it to 6 days. How do i proceed Do you mean 6 working days in a week? If so, try =SUMPRODUCT(INT((MAX(end_date,start_date)-WEEKDAY(MAX(end_date,start_date)+1 -{2;3;4;5;6;7})-MIN(end_date,start_date)+8)/7)) -SUMPRODUCT(ISNUMBER(MATCH(WEEKDAY(holidays),{2;3;4;5;6;7},0))*(holidays>=MI N(end_date,start_date))*(holidays<=MAX(end_date,start_date))) This assume Mon-Sat, so just change the array 2;3;4;5;6;7 to 1;2;3;4;5;6 if you want Sun-Fri. -- HTH Bob Phillips (remove nothere from e...

Matching number formats
I am using an INDEX/MATCH formula and do get a "VALUE NOT AVAILABLE" response. Both ranges have a "General" format. A [Copy][Paste Special][Formats] does not make the formats match. How can I make them respond to each other? On Thu, 12 May 2005 10:36:09 -0700, "raystub" <raystub@discussions.microsoft.com> wrote: >I am using an INDEX/MATCH formula and do get a "VALUE NOT AVAILABLE" >response. Both ranges have a "General" format. A [Copy][Paste >Special][Formats] does not make the formats match. How can I make them >resp...

Resetting Autonumber field
Can anyone tell me how I can reset the Autonumber field in my table? Compacting a database with an empty table will do that Pieter "Firz" <Firz@discussions.microsoft.com> wrote in message news:AE025D3B-EF2E-48E8-B7F9-66A442D1AE73@microsoft.com... > Can anyone tell me how I can reset the Autonumber field in my table? Compact and repair will do it. -- "Loose Change 2nd Edition" has been seen by almost 7 million people on Google video "Firz" wrote: > Can anyone tell me how I can reset the Autonumber field in my table? You've already re...

Get paid while you get online!!
I found a great Internet company - Cashfiesta.com - that has created a product everyone can benefit from. They pay you while you work or play on your computer. All you need to do is keep their software - the FiestaBar=99 - active while you are online. They even pay you when your friends are using their computers. Unlike other companies, Cashfiesta gives you control over how much money you earn. They have an individual payrate based on the number of Special Offers you sign up for. As some of these offers are free, you can increase your payrate up to 33 times without spending a penny. It's...

Can't get auto-update (update) to install
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC I've been trying to manually check for updates to Word 2008, and I get a &quot;critical update&quot; notice, asking me to install auto-update. When I try to install it, I cannot. It just keeps repeating the attempt, in an &quot;endless loop.&quot; What to do? <br> Thank you. ...

Spreadsheet getting corrupted
Hello All: I have a relatively large spreadsheet. I am getting errors (see after my signature line). What could be causing these errors? Is it that the spreadsheet is too large? Thanks Deguza -------------------------------------------------------- Microsoft Office Excel File Repair Log Errors were detected in file 'C:\Documents and Settings\deguza\My Documents\sales\Sales_2006_2007.xls' The following is a list of repairs: Global PivotTable report information was repaired due to integrity problems. Global PivotTable report information was repaired due to integrity problems. Glo...