Thread: printf() format

    #1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Hong Kong
    Posts
    71
    Rep Power
    15
    I have a problem to output the format of printf().

    <?
    $year=2000;
    $month=7;
    $day=9;

    printf("%d%d%d",$year,$month,$day);
    ?>

    How to output to "20000709" using printf()? I must use the function printf(). Thank you!
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    3
    Rep Power
    0
    Try (again...):

    printf ("%d%02d%02d", $year, $month, $day);

    HTH,

    Chris

    [This message has been edited by Datura (edited July 10, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    36
    Rep Power
    15
    I dont use this format and am not up on it but that format is generaly used with a query ie
    printf("%s %s %s", $myrow["year"], $myrow["month"], $myrow["day"]);

    From your example just use
    echo $year $month $day;

    anyone else?

    Bill
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    This can be used with anytthing I noticed that you try to assign the extra 0 in the month and day; why not just make your variables
    $month = "07";
    $day = "09";
    As for printf this is the format, I prefer single quotes so I can use double quotes inside the statement:
    printf('%s%s%s', $year, $month, $day);

Similar Threads

  1. printf
    By ponloeu in forum C Programming
    Replies: 6
    Last Post: February 17th, 2004, 12:16 AM
  2. send and recv problem in sockets
    By paulr1984 in forum C Programming
    Replies: 4
    Last Post: December 15th, 2003, 11:02 PM
  3. problem printf and text format
    By yannoush in forum C Programming
    Replies: 1
    Last Post: November 4th, 2003, 03:11 AM
  4. looping gone wrong
    By Angelo in forum C Programming
    Replies: 24
    Last Post: October 15th, 2003, 06:41 AM
  5. Interpolating scalar variable in printf statement
    By raklet in forum Perl Programming
    Replies: 2
    Last Post: August 19th, 2003, 11:06 AM

IMN logo majestic logo threadwatch logo seochat tools logo