What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Formula to calculate days lived?

Formula to calculate days lived?
Author: Message:
albert
Veteran Member
*****

Avatar

Posts: 2247
Reputation: 42
– / Male / Flag
Joined: Feb 2005
O.P. Undecided  Formula to calculate days lived?
I'm coding this program in Java and I absolutely need a formula to be able to calculte the numbers of days lived.

I searched the net, I couldn't find much.

What I came up with is this :

[ {365 * (currentyear -yearborn)} + {(currentyear -yearborn) / 4} ] - [(daysofyearthatpassed*) + (dayborn)] + [(daysofyearthatpassed*)+(currentday)]


daysofyearthatpassed* : depending on which month and if the year has 366 or 365 days, I calculated an amount that I just add to the day.



As you can see this isn't working.. So if you guys find a better way or can actually correct this, please don't be shy to do so.
11-11-2006 09:14 PM
Profile E-Mail PM Web Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
Joined: Jul 2006
RE: Formula to calculate days lived?
couldn't you just use something like:
Date today = new Date();
Date birth =new Date(.....);

and subtract them? although the date object sucks in java...
and semi-replaced by Calender... maybe the api is more helpfull...
11-11-2006 10:24 PM
Profile E-Mail PM Find Quote Report
qgroessl
Veteran Member
*****


Posts: 1615
Reputation: 22
33 / – / Flag
Joined: Jul 2005
Status: Away
RE: Formula to calculate days lived?
No... cause you'd need to add in leap years and such.
11-11-2006 10:25 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Formula to calculate days lived?
quote:
Originally posted by alby
I searched the net, I couldn't find much.
I searched the net and found tons :p

search with "Java Datediff" ;)

http://forum.java.sun.com/thread.jspa?threadID=48...&messageID=2292012
http://forum.java.sun.com/thread.jspa?forumID=31&threadID=395202
http://www.java2s.com/Code/Java/Development-Class...etweentwodates.htm
http://jalbum.net/api/se/datadosen/util/Dates.html
http://www.rupertjones.com/dateutil/docs/api/com/...util/DateDiff.html
etc

quote:
Originally posted by UTI
No... cause you'd need to add in leap years and such.
I dunno exactly for Java, but in any other language I know Date objects are in milliseconds or at least in seconds or another form which you can substract from each other.

You do not need to take in account leap years, lead days and leap seconds. This is automatically done as the calenders of the objects use Gregorian calenders.

But as said, I dunno if this is also the case in Java (but I would be surprised if it wasn't)...

This post was edited on 11-12-2006 at 12:43 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
11-12-2006 12:37 AM
Profile PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Formula to calculate days lived?
quote:
Originally posted by CookieRevised
I dunno if this is also the case in Java
The Java Date object (and anything to do with dates) uses the Gregorian calendar, and will correctly deal with leap years.
[Image: spartaafk.png]
11-12-2006 03:44 PM
Profile PM Web Find Quote Report
fluffy_lobster
Veteran Member
*****

Avatar
Posts: -2

Posts: 1391
Reputation: 23
36 / Male / Flag
Joined: Nov 2002
RE: Formula to calculate days lived?
this is why dates need to go metric...
11-12-2006 08:18 PM
Profile E-Mail PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Formula to calculate days lived?
quote:
Originally posted by fluffy_lobster
this is why dates need to go metric...
They'll never go metric, simply because it's not possible to define a metric system for dates that everyone understands. Look at Swatch's failed .beat system for instance.
[Image: spartaafk.png]
11-12-2006 10:46 PM
Profile PM Web Find Quote Report
rav0
Veteran Member
*****

Avatar
i have an avatar

Posts: 1419
Reputation: 29
34 / Male / Flag
Joined: Aug 2003
RE: RE: Formula to calculate days lived?
quote:
Originally posted by fluffy_lobster
this is why dates need to go metric...

Yep, well, we need a decimal calendar (metric means based on the metre). Problem is, days and years are both determined by Earth's movement. You can't make up an arbitary unit like the metre, a year has 365 days (and a bit), that's just the way it is.
| [Image: dorsh] |

(\ /)
(O.o)
(> <)

This is Bunny. Copy Bunny into your signature to help him on his way to world domination
11-13-2006 06:24 AM
Profile E-Mail PM Web Find Quote Report
Jarrod
Veteran Member
*****

Avatar
woot simpson

Posts: 1304
Reputation: 20
– / Male / Flag
Joined: Sep 2006
RE: Formula to calculate days lived?
just use the counter psm script or the holiday counter have a look at how they did it

This post was edited on 11-14-2006 at 10:59 AM by Jarrod.

[Image: 5344.png]
[Image: sig.png]

A.k.a. The Glad Falconer














11-14-2006 10:58 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On