calculating the difference of to dates

Discussion in 'Ruby' started by Jochen Kaechelin, Aug 9, 2007.

  1. 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


    --
    Jochen Kaechelin
    railswerk.de, gissmoh.de, figgfrosch.de, ror-ror.de
     
    Jochen Kaechelin, Aug 9, 2007
    #1
    1. Advertising

  2. Jochen Kaechelin

    Konrad Meyer Guest

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

    On Thursday 09 August 2007 01:29:46 am Jochen Kaechelin wrote:
    > 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 <> 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--
     
    Konrad Meyer, Aug 9, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    869
    Rob Schieber
    Sep 30, 2005
  2. Toine

    Calculating future dates

    Toine, Feb 2, 2007, in forum: Python
    Replies:
    4
    Views:
    276
    Ben Finney
    Feb 2, 2007
  3. celsius
    Replies:
    2
    Views:
    489
    Stan Milam
    Jan 5, 2005
  4. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    199
    Mark Schupp
    Aug 9, 2004
  5. Yotam
    Replies:
    4
    Views:
    614
    Dr J R Stockton
    Nov 10, 2006
Loading...

Share This Page