Need to know time passed since a date
and represent the result in Years, Months and Days and combinations.
If the results does not have Months, show only Years and Days
If the result does not have Days, Show only Years and Months
Also to show total Months and Days.
Also to show total Days.
For example:
Today is: Jan 9, 2014
I have a dates like this:
1) Jan 9, 1967
The results should be:
47 Years passed since 1)
Total (x) Months + (y) Days
Total (z) Days
2) Jan 8, 1967
The results should be:
47 Years and 1 Day passed since 2)
Total (x) Months + (y) Days
Total (z) Days
3) Dec 9, 1966
The results should be:
47 Years and 1 Month passed since 3)
Total (x) Months + (y) Days
Total (z) Days
Are there a standard package to do that?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
In the code resolution is a year.If I change the initial date from Jan 9, 1967 to:Jan 8, 1967
it still shows 47 year passed, while actually it is 47 years and 1 day.Also not all years have 365 days, not all months have 30,
and these should be not hard coded. The result should be precise.
By "package" I thought there is a package for more sophisticatedfunctionality like this.On Friday, January 10, 2014 12:56:01 AM UTC-8, Svip Pong wrote:On 10 January 2014 06:23, Constantine Vass <ths...@gmail.com> wrote:
> Are there a standard package to do that?
How about this?
http://play.golang.org/p/GBd3tJWe79
--
--
I’m pretty sure the only way of calculating this is to iterate through the years, months, and days:
Considering that either of these operations would likely take at least several seconds to do so
0 - 0.5 - 1/2 year since data of sale0.6 - 1 - more than 1/2 year since data of sale1 - one year since data of sale
1 - 1.5 - less than 1 and 1/2 year since data of sale
1.5 - 2 - 2 years since data of sale
20130801 -20140101 - today
days since:153.000000
years precise:0.418886 - less than 1/2 year
approximate full years since:0
20130501 -
20140101 - today
days since:245.000000
years precise:0.670765 - more than 1/2 year
approximate full years since:1
20120101 -20140101 - today
days since:731.000000
years precise:2.001344 - 2 years exact
approximate full years since:2
days since:365.000000 years precise:0.999303approximate full years since:1 - 1 year exact
20120801 -
20140101 - todaydays since:518.000000 years precise:1.418189 - less than 1 and 1/2 yearapproximate full years since:1
20120401 -20140101 - today
days since:640.000000 years precise:1.418189years precise:1.752203 -more than 1 and 1/2 year
approximate full years since:2
it still shows 47 year passed, while actually it is 47 years and 1 day.Also not all years have 365 days, not all months have 30,and these should be not hard coded. The result should be precise.
1. Reason about differences in the Year, Month, and Day of start and end. (dates)2. Reason about the difference in days or subdays between start and end. (duration)
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
OK. So when one month passes that means one calendar month, right? April->May. That has nothing to do with the number of days in a month because it just means "number of times the month name changed." Thus the 360 and 30 and leap year (4, 100, 400) calendrical equations are irrelevant. If so, the perfect answer is posted above by Bakul.