SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: parsing numbers

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    parsing numbers

    I'm trying to make a date converter and I can't figure out how to parse the code that we are going to use (122301 for todays date) and have it display December 23, 2001. Any help will be greatly appreciated.
    -Magriep

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am assuming then that you have your date packed into a string in this format:

    MMDDYY

    PHP Code:
    <?php

    $packedDateStr 
    '122301';

    // unpack the string and break it up
    // into year, month, day values
    $year substr($packedDateStr42);
    $month substr($packedDateStr22);
    $day substr($packedDateStr02);

    // do some Y2K fiddling to get the year into
    // four digits
    $year = ($year 50) ? "19$year"20$year";

    // make a timestamp
    $timeStamp mktime(000$month$day$year);
    // convert the timestamp into a formatted 
    // date string
    $formattedDate date("F D Y"$timeStamp);
    echo 
    $formattedDate;
    ?>
    note that is untested code. Give it a whirl and see how it works for you.

    consult the manual for more information on
    www.php.net/substr
    www.php.net/date
    www.php.net/mktime
    also related:
    www.php.net/strtotime

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Same result, a few less steps.

    PHP Code:
    <?
    $oStr 
    122301;
    $array split("\r\n"chunk_split($oStr2));
    $time mktime(0,0,0,$array[0],$array[1],$array[2]);
    print 
    date("F j, Y"$time); 
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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