dates, scheduling tasks, mysql

Discussion in 'Ruby' started by Comfort Eagle, Nov 30, 2006.

  1. What is the best Date format for working with dates in ruby & mysql?

    I have a recurring task that once complete I want to update the db to
    reflect the next time to do it.

    "2006-11-30" as a string ends up being just "2006".

    tnx in advance.

    --
    Posted via http://www.ruby-forum.com/.
    Comfort Eagle, Nov 30, 2006
    #1
    1. Advertising

  2. Paul Lutus wrote:
    > Comfort Eagle wrote:
    >
    >> What is the best Date format for working with dates in ruby & mysql?

    >
    > As to MySQL, you really need to stick to a strict date format of
    > yyyy-mm-dd.
    > This is MySQL's date format when shown in plain text.
    >
    >> I have a recurring task that once complete I want to update the db to
    >> reflect the next time to do it.
    >>
    >> "2006-11-30" as a string ends up being just "2006".

    >
    > This didn't happen by magic, you created it with some code. If you show
    > us
    > the code, we will show you the magic.



    class Date
    def Date.now
    return Date.jd(DateTime.now.jd)
    end
    end

    url ='http://xxx.com'
    begin
    date = Date.now.to_s
    p date
    dbh = Mysql.real_connect("localhost", "xxx", "xxxx", "xxxxx")
    chg = dbh.query("UPDATE sites set updated='#{date}' where
    url='#{url}'")

    --
    Posted via http://www.ruby-forum.com/.
    Comfort Eagle, Nov 30, 2006
    #2
    1. Advertising

  3. Comfort Eagle wrote:
    > Paul Lutus wrote:
    >
    >> Comfort Eagle wrote:
    >>
    >>
    >>> What is the best Date format for working with dates in ruby & mysql?
    >>>

    >> As to MySQL, you really need to stick to a strict date format of
    >> yyyy-mm-dd.
    >> This is MySQL's date format when shown in plain text.
    >>
    >>
    >>> I have a recurring task that once complete I want to update the db to
    >>> reflect the next time to do it.
    >>>
    >>> "2006-11-30" as a string ends up being just "2006".
    >>>

    >> This didn't happen by magic, you created it with some code. If you show
    >> us
    >> the code, we will show you the magic.
    >>

    >
    >
    > class Date
    > def Date.now
    > return Date.jd(DateTime.now.jd)
    > end
    > end
    >
    > url ='http://xxx.com'
    > begin
    > date = Date.now.to_s
    > p date
    > dbh = Mysql.real_connect("localhost", "xxx", "xxxx", "xxxxx")
    > chg = dbh.query("UPDATE sites set updated='#{date}' where
    > url='#{url}'")
    >
    >

    Not sure why exending Date doesn't work (at least in irb), but I believe you
    want to be defining the method 'now' (not Date.now??)

    As an alternate way to do this you could try

    $ irb
    irb(main):001:0> date = Time.now.strftime('%Y-%m-%d')
    => "2006-12-05"
    irb(main):002:0>

    hth,
    Vance
    Vance A Heron, Dec 5, 2006
    #3
  4. Vance A Heron wrote:
    > Comfort Eagle wrote:
    >>>

    >>
    >> p date
    >> dbh = Mysql.real_connect("localhost", "xxx", "xxxx", "xxxxx")
    >> chg = dbh.query("UPDATE sites set updated='#{date}' where
    >> url='#{url}'")
    >>
    >>

    > Not sure why exending Date doesn't work (at least in irb), but I believe
    > you
    > want to be defining the method 'now' (not Date.now??)
    >
    > As an alternate way to do this you could try
    >
    > $ irb
    > irb(main):001:0> date = Time.now.strftime('%Y-%m-%d')
    > => "2006-12-05"
    > irb(main):002:0>


    Hmm

    Sorry I meant to write back... the above code works when you setup your
    mysql tables properly for accepting dates.

    --
    Posted via http://www.ruby-forum.com/.
    Comfort Eagle, Dec 5, 2006
    #4
    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:
    829
    Rob Schieber
    Sep 30, 2005
  2. Joe

    Scheduling Tasks

    Joe, Mar 5, 2004, in forum: C++
    Replies:
    5
    Views:
    1,694
    Karl Heinz Buchegger
    Mar 5, 2004
  3. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    166
    Mark Schupp
    Aug 9, 2004
  4. Replies:
    1
    Views:
    191
    Jano Svitok
    Jul 17, 2007
  5. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    166
    Eric I.
    Jun 8, 2008
Loading...

Share This Page