Professional Web Applications Themes

Date problem - PERL Beginners

Hi All, I am facing this strange problem related to dates. When I print the date using the system's date command, it prints correctly. But when I do the same using localtime, it shows the month as wrong (1 month previous. bash-2.03$ perl -e 'a=localtime; print "a\n"' 18 4 8 26 3 104 1 116 0 ^^^ bash-2.03$ perl -e 'a=localtime(time); print "a\n"' 20 4 8 26 3 104 1 116 0 ^^^ bash-2.03$ date Mon Apr 26 08:04:23 GMT 2004 bash-2.03$ It shows the month as March (3) instead of April. What could I be doing wrong? Thanks in ...

  1. #1

    Default Date problem

    Hi All,

    I am facing this strange problem related to dates.
    When I print the date using the system's date command,
    it prints correctly. But when I do the same using
    localtime, it shows the month as wrong (1 month
    previous.

    bash-2.03$ perl -e 'a=localtime; print "a\n"'
    18 4 8 26 3 104 1 116 0
    ^^^
    bash-2.03$ perl -e 'a=localtime(time); print "a\n"'
    20 4 8 26 3 104 1 116 0
    ^^^
    bash-2.03$ date
    Mon Apr 26 08:04:23 GMT 2004
    bash-2.03$

    It shows the month as March (3) instead of April. What
    could I be doing wrong?

    Thanks in Advance




    __________________________________
    Do you Yahoo!?
    Yahoo! Photos: High-quality 4x6 digital prints for 25
    http://photos./ph/print_splash
    Alok Guest

  2. #2

    Default Re: Date problem

    On Monday 26 April 2004 06:07, Alok Bhatt wrote: 

    Hello,
     

    localtime() and gmtime() return months in the range 0 to 11 so 3 is
    April.

    perldoc -f localtime
    perldoc -f gmtime


    John
    --
    use Perl;
    program
    fulfillment

    John Guest

  3. #3

    Default Re: Date problem

    On Monday 26 April 2004 03:07 am, Alok Bhatt wrote: 

    Check the docs: the months go from 0..11 in localtime.

    Aloha => Beau;

    Beau Guest

  4. #4

    Default Re: Date problem

    Hi,

    Thanks everyone for the answer.

    So silly of me. Didnt check the docs :$


    --- Patrick Heffernan <net.au> wrote: 
    > command, 
    > [Snip] 
    > What 
    >
    > I'm only a raw beginner in Perl, so hopefully I'm
    > giving you the right
    > information. I'm sure others in the list will point
    > out my mistakes :)
    >
    > localtime returns the following:
    >
    >[/ref]
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) 





    __________________________________
    Do you Yahoo!?
    Yahoo! Photos: High-quality 4x6 digital prints for 25
    http://photos./ph/print_splash
    Alok Guest

  5. #5

    Default Re: Date problem


    On Mon, 26 Apr 2004 06:07:03 -0700 (PDT)
    Alok Bhatt hammered out:
     
    [Snip] 

    I'm only a raw beginner in Perl, so hopefully I'm giving you the right
    information. I'm sure others in the list will point out my mistakes :)

    localtime returns the following:

    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st)

    with $mon, the month, being in the range (0 .. 11). So January is 0 to
    December being 11. You aren't doing anything wrong, just misinterpreting
    the information.

    HTH

    --
    Patrick Heffernan * Over the years, I've developed my sense of
    Maryvale Computer Service * deja vu so acutely that now I can remember
    Warwick - QLD * things that *have* happened before ...
    07 4667 3807 *

    Patrick Guest

Similar Threads

  1. date problem
    By Simon in forum Coldfusion - Getting Started
    Replies: 26
    Last Post: February 14th, 09:15 AM
  2. date query problem, date in variable
    By roy in forum MySQL
    Replies: 1
    Last Post: October 16th, 11:57 AM
  3. PHP Date Problem
    By Vincent J. Gullotta in forum PHP Development
    Replies: 4
    Last Post: February 4th, 10:00 PM
  4. [PHP] date problem
    By Robert Cummings in forum PHP Development
    Replies: 0
    Last Post: September 24th, 05:33 PM
  5. Problem with date('w')
    By Beoi 7308 in forum PHP Development
    Replies: 2
    Last Post: August 25th, 11:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139