[Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register]

Author Message
azrael_demon
General User

Joined: 01 May 2008
Posts: 9

 Posted: Wed May 07, 2008 6:29 pm    Post subject: How to count number of days using calc Hi i got one problem, i wish to count the number of days using calc but i dont know can, there is an example: "25/04/1999 19/09/2004" using this two date i want to know how many days and/or month are there? Thanks
Mr5o1
Power User

Joined: 05 Dec 2007
Posts: 52

Posted: Wed May 07, 2008 7:04 pm    Post subject:

Firstly, is that two date string contained in -one- cell? or two different ones? if its one cell, you'll first need to split them in two, using LEFT and RIGHT functions (assuming the date formats will always be the same, otherwise it can still be done but is a little more complicated)

Once they're in seperate cells.. lets say:
A1: 25/04/1999
B1: 19/09/2004

then you could use the following in C1 to calculate the # of months
 Code: =MONTHS(A1;B1;0)

and the following in D1 to calculate the # of days
 Code: =(EOMONTH(A1;0)-A1)+(B1-EOMONTH(A1;D1))

Hope this helps!
azrael_demon
General User

Joined: 01 May 2008
Posts: 9

 Posted: Wed May 07, 2008 10:53 pm    Post subject: How to count number of days using calc ok but what if the format is in YYYYMMDD, it look like doesnt work pls advise
Mr5o1
Power User

Joined: 05 Dec 2007
Posts: 52

Posted: Thu May 08, 2008 4:51 pm    Post subject:

sorry... my bad, should be:
 Code: =(EOMONTH(A1;0)-A1)+(B1-EOMONTH(A1;C1))

the second EOMONTH should be A1;C1 not A1;D1 like I listed before.. the second field should be the number of months we calculated with the months function. sorry about that...

I tried it with YYYYMMDD (and YYYY-MM-DD in case thats what you meant?) and it works fine, so long as the two date cells are formatted appropriately, and C1 & D1 are formatted as numbers.
Villeroy
Super User

Joined: 04 Oct 2004
Posts: 10065
Location: Germany

 Posted: Fri May 09, 2008 3:42 am    Post subject: Two dates in A1 and B1 you get the difference by substracting one from the other =B1-A1 or =A1-B1 respectively. Dates are nothing but specially formatted number in unit "Days". Get the hours: =(B1-A1)*24_________________Rest in peace, oooforum.org Get help on http://forum.openoffice.org
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 8 Hours Page 1 of 1

 Jump to: Select a forum OpenOffice.org Forums----------------Setup and TroubleshootingOpenOffice.org WriterOpenOffice.org CalcOpenOffice.org ImpressOpenOffice.org DrawOpenOffice.org MathOpenOffice.org BaseOpenOffice.org Macros and APIOpenOffice.org Code Snippets Community Forums----------------General DiscussionSite Feedback
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group