Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Posts
    232

    Arrow Unanswered: batch file with dates

    I want to run a batch file that contains (copy ,other commands) on window 2000

    that batch file should run at 2 am it gets the system date (month and day)-1
    meaning previos day

    (jan23rd) and join with a batch file myfile 122 (on windows 2000)

    and for oct should be A22, noV should be B22 AND

    DEC Should be C22

    real catch is on 1st feb should be 131(jan 31st) etc for each month

    THANKS
    bigfoots

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd use:
    Code:
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
    =  localtime(time() - 86400);
    $filename = sprintf("%X%02d", 1 + $mon, $mday);
    -PatP

  3. #3
    Join Date
    Jun 2004
    Location
    Singapore
    Posts
    28
    Hi Pat Phelan,

    I'm trying to get my date and time in the format (dd/mm/yyyy hh:mm:ss)
    below is my code, can you advise on what is wrong with it?

    $time = localtime;
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) = localtime($time);
    print "<BR>$mday/$mon/$year $hour:$min:$sec<BR>";

    and my output turn up to be "1/0/70 8:0:0", which is not what I want.

    Also as I'm a newbie in perl, can you advise on some websites which I can refer to.

    Thanks alot.
    oks

    Quote Originally Posted by Pat Phelan
    I'd use:
    Code:
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
    =  localtime(time() - 86400);
    $filename = sprintf("%X%02d", 1 + $mon, $mday);
    -PatP
    ps: By the way why minus 86400?

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Something seems to be kind of confused with your year, but I'd use:
    Code:
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
    $formatted_time = sprintf("<BR>%02d/%02d/%04d %02d:%02d:%02d<BR>"
    , $mday, 1 + $mon, 1900 + $year, $hour, $min, $sec);
    print $formatted_time;
    At least in most implementations of localtime(), Months are 0 - 11 and years are relative to 1900, so I added the appropriate offset values.

    There are 86400 seconds in a standard day (24 hours times 60 minutes times 60 seconds). The time() function returns the seconds since the epoch, and the localtime function mangles the seconds into more conventional units of time. By subtracting 86400 seconds from the current time, I "back up" one day to get yesterday's date as sjumma requested.

    -PatP

Posting Permissions

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