Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    30

    Unhappy Unanswered: retrieving date without sec, min, hour

    i've tried the following to get my current year, month & date
    Code:
    $today   = time ();
    ($t_sec, $t_min, $t_hour, $t_mday, $t_mon, $t_year) = localtime($today);
    $t_year = substr($t_year, 1,2);
    $t_mon++;
    
    print "$y_year/$t_mon/$t_mday";
    It works fine, but give me the following warning which is really annoying..

    Name "main::t_sec" used only once: possible typo at ***.pl line 17.
    Name "main::t_min" used only once: possible typo at ***.pl line 17.
    Name "main::t_hour" used only once: possible typo at ***.pl line 17.

    hmm.. anyway to retrieve current date only?

  2. #2
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    have you tried a slice?

    ($t_mday, $t_mon, $t_year) = localtime($today)[3,4,5];

    Code:
    $today=time();
    print join('/',(localtime($today))[3,4,5]),"\n";

  3. #3
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Code:
    my ($day,$mon,$year) = (localtime(time))[3..5];
    $date = sprintf("%02d/%02d/%04d",$day,$mon+1,$year+1900);
    print $date;
    Don't forget to add 1 to the month and 1900 to the year!
    board.perl-community.de - The German Perl-Community

  4. #4
    Join Date
    Jul 2004
    Posts
    30

    Thumbs up

    thanks reneeb & senze,

    i didnt know that i can specify like that!
    thanks a lot !
    searching all on the web, but only get to see
    ($t_sec, $t_min, $t_hour, $t_mday, $t_mon, $t_year) = localtime($today);

    thanks again!

Posting Permissions

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