Cariamole
Cariamole

Reputation: 406

difference of year between two date

I need to know the difference of year between two date. The only information I got at this moment, is, for example:

Select ((JulianDay('now')) - JulianDay(2008-09-02))

And I receive this : 2455510.12568118 How to transform this number into year

Upvotes: 1

Views: 3474

Answers (2)

John Doe
John Doe

Reputation: 158

You should offer more information about what you are doing. It appears that you're working with SQLite, is this correct? If so, then the use of JulianDay will return the difference in days with fractions of days included. To turn this number into a year you should divide the number of days by 365.25 (as there are 365.25 days in a year), this would leave you with the number of years.

Your syntax would probably be something like: Select ((JulianDay('now')) - JulianDay(2008-09-02)) / 365.25

If you want to round the years over to remove fractions of a year you could probably do so like: SELECT round ((JulianDay('now') - JulianDay(2008-09-02) / 365.25);

I don't guarantee any of my syntax, as I've never worked with SQLite before. Best of luck.

Upvotes: 0

trincot
trincot

Reputation: 350300

You should put the second date in quotes, because now you subtract 9 from 2008 and then subtract another 2.

Then you'll get the number of days between the two days. To convert to years, you could divide by 365.25:

Select ((JulianDay('now')) - JulianDay('2008-09-02'))/365.25

Upvotes: 3

Related Questions