calculating the difference of to dates

  • Thread starter Jochen Kaechelin
  • Start date
J

Jochen Kaechelin

I want to calculate the difference (days, hours, minutes)
between a given date out of a mysql database (2007-07-07, date) and
the current date (Time.now).

How can I achieve this?

Thanx
 
K

Konrad Meyer

--nextPart1227098.0ikUsyLUI4
Content-Type: text/plain;
charset="iso-8859-15"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I want to calculate the difference (days, hours, minutes)
between a given date out of a mysql database (2007-07-07, date) and
the current date (Time.now).
=20
How can I achieve this?

ex:

require 'parsedate'

sql_time =3D Time.mktime(*ParseDate.parsedate("2007-07-07"))
cur_time =3D Time.now

difference =3D cur_time - sql_time # result will be in seconds

Hope that helps.
=2D-=20
Konrad Meyer <[email protected]> http://konrad.sobertillnoon.com/

--nextPart1227098.0ikUsyLUI4
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBGut1rCHB0oCiR2cwRAoWLAJ4p/QWe4M71ET7Qp8o/U464610eXgCgvtjI
74bcOxdt0Jnig1Vs4HTveNY=
=4e82
-----END PGP SIGNATURE-----

--nextPart1227098.0ikUsyLUI4--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top