how to store my date in variables using locatime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poolboi
    New Member
    • Jan 2008
    • 170

    how to store my date in variables using locatime

    hey guys,

    [CODE=perl]
    ($sec, $min, $hrs, $day, $month, $year) = (localtime) [0,1,2,3,4,5];
    printf("%04d-%02d-%02d\n", $year+1900, $month+1, $day);
    [/CODE]

    the above right print the date say today:
    2008-05-13

    how do i store the in a variable say $date
    cos i want to use it later in the later part of my script
    thanks
  • nithinpes
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    Code:
    ($sec, $min, $hrs, $day, $month, $year) = (localtime) [0,1,2,3,4,5];
    $date = sprintf("%04d-%02d-%02d\n", $year+1900, $month+1, $day);
    print "$date";
    The sprintf() function is used to format string/variables and return the formatted string to a variable.

    Comment

    • poolboi
      New Member
      • Jan 2008
      • 170

      #3
      thanks a lot nithinpes..u helped me a lot

      Comment

      Working...