DateTime confusion

Discussion in 'Ruby' started by christriddle@googlemail.com, Oct 12, 2007.

  1. Guest

    Hello!
    Wondered if anyone could help...
    I'm trying to parse a datetime

    date = DateTime.parse("200701011900")

    Which gives me a datetime. When i print it, it gives:
    2007-01-01T19:00:00+00:00=> nil

    but when I try:

    print date.year

    it gives me an unknown method error.... any ideas what I'm doing
    wrong?

    Cheers!
    Chris
     
    , Oct 12, 2007
    #1
    1. Advertising

  2. Guest

    On 12 Oct, 14:39, ""
    <> wrote:
    > Hello!
    > Wondered if anyone could help...
    > I'm trying to parse a datetime
    >
    > date = DateTime.parse("200701011900")
    >
    > Which gives me a datetime. When i print it, it gives:
    > 2007-01-01T19:00:00+00:00=> nil
    >
    > but when I try:
    >
    > print date.year
    >
    > it gives me an unknown method error.... any ideas what I'm doing
    > wrong?
    >
    > Cheers!
    > Chris


    Don't worry guys, just being an idiot!
    Cheers
     
    , Oct 12, 2007
    #2
    1. Advertising

  3. 7stud -- Guest

    wrote:
    > Hello!
    > Wondered if anyone could help...
    > I'm trying to parse a datetime
    >
    > date = DateTime.parse("200701011900")
    >
    > Which gives me a datetime. When i print it, it gives:
    > 2007-01-01T19:00:00+00:00=> nil
    >
    > but when I try:
    >
    > print date.year
    >
    > it gives me an unknown method error.... any ideas what I'm doing
    > wrong?
    >
    > Cheers!
    > Chris


    It works fine for me, although I wouldn't name the variable 'date' since
    it is the same name as the file you are including.

    require 'date'

    date = DateTime.parse("200701011900")
    puts date.year

    --output:--
    2007
    --
    Posted via http://www.ruby-forum.com/.
     
    7stud --, Oct 12, 2007
    #3
    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. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    759
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    597
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    440
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    376
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    801
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page