Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Date Display

by keafb (Initiate)
on Jun 08, 2001 at 01:09 UTC ( [id://86754]=perlquestion: print w/replies, xml ) Need Help??

keafb has asked for the wisdom of the Perl Monks concerning the following question:

Is there a script that can print today's date in the following format, 06/11/01? Thanks!

Replies are listed 'Best First'.
Re: Date Display
by virtualsue (Vicar) on Jun 08, 2001 at 02:43 UTC
    Can you show us what you've got so far?

    perldoc -f localtime is the traditional starting place for date & time. Pay particular attention to the "odd" values returned for the month & year.

    As you probably already know, the slightly tricky part is getting the leading zeros. You can do something basic, like:

    ($day < 10) && ($day = "0$day"); ($month < 10) && ($month = "0$month");
    Or, you could use a standard function which allows you to specify padding values for fields (sprintf), An even better choice is strftime, which was especially written to handle date/time values. This site is a treasure trove of articles written by people who have asked similar questions in the past. The best way to find this material is to use Super Search. I just did, and found several articles that will help you with this question.
Re: Date Display
by da (Friar) on Jun 08, 2001 at 01:13 UTC
    use Date::Format; print time2str( "%D", time );
    Check out this node which answers nearly the exact same question, with lots of discussion.

    ___
    -DA

Re: Date Display
by davorg (Chancellor) on Jun 11, 2001 at 12:14 UTC

    Your question is a little unclear, it's impossible to be sure what date format you mean - is that MM/DD/YY or the far more logical DD/MM/YY.

    And didn't the last couple of years teach you anything about the dangers of two digit dates?

    ISO has a standard format for dates and it's pretty good as it's a) sortable and b) unambiguous. Why not format your dates like this: YYYY-MM-DD.

    Oh, and Perl comes with a built-in function to produce dates in any format, lookup the docs for POSIX::strftime.

    --
    <http://www.dave.org.uk>

    Perl Training in the UK <http://www.iterative-software.com>

Re: Date Display
by JP Sama (Hermit) on Jun 08, 2001 at 01:49 UTC
    why don't you SEARCH before asking such a simple question!?!?

    If you want somebody to do your work, i believe that's the wrong place to ask!

    Shame on you!

    #!/jpsama/bin/perl -w
    $tks = `mount`;
    $jpsama = $! if $!;
    print $jpsama;
    
Re: Date Display
by JP Sama (Hermit) on Jun 08, 2001 at 21:19 UTC
    Well, I believe i was a litle rude, and for that i apologize.

    But, i still think that you should SHOW us that you tried something... eg. post the CODE you're doing.. ok?

    I will be really glad to help you with your scripts...

    Regards

    #!/usr/bin/perl -w $mount = `mount`; $error = $! if $!; print $mount; print $error;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://86754]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found