if a number is say xx how to make it 20xx, but ignore if it is xxxx?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Biscuit Eater

    if a number is say xx how to make it 20xx, but ignore if it is xxxx?

    Ok, I am almost finished with what I was trying to accomplish (pulling
    future events from a csv file where the first field is the date). I was
    concerned that though I wanted dates entered as mm-dd-yyyy, people often
    drop the leading zeros and enter yy. I think I have figured out a way to
    cover the leading zeros using sprintf. The problem is now converting
    something like 04 to 2004.

    This is what I have so far:

    <?

    $readfile = file("events.tx t");

    for ($k=0; $k<=count($read file)-1; $k++) {
    $field = split(";",$read file[$k]);

    $date = date("Ymd");

    $piece = explode("-", $field[0]);
    $day = sprintf("%02d", $piece[1]);
    $month = sprintf("%02d", $piece[0]);
    $array = array($piece[2], $month, $day);
    $c = implode("", $array);
    if ($c >= $date) {

    print ("$month/$day/$piece[2] $field[1] $field[2], etc.<br>");

    }
    }

    ?>

    Any thoughts would be appreciated.

    Bill


  • Jon Kraft

    #2
    Re: if a number is say xx how to make it 20xx, but ignore if it is xxxx?

    The Biscuit Eater <BoulderBill*NO SPAM*@comcast.n et> wrote:
    [color=blue]
    > Ok, I am almost finished with what I was trying to accomplish (pulling
    > future events from a csv file where the first field is the date). I was
    > concerned that though I wanted dates entered as mm-dd-yyyy, people often
    > drop the leading zeros and enter yy. I think I have figured out a way to
    > cover the leading zeros using sprintf. The problem is now converting
    > something like 04 to 2004.
    >
    > This is what I have so far:
    >
    > <?
    >
    > $readfile = file("events.tx t");
    >
    > for ($k=0; $k<=count($read file)-1; $k++) {
    > $field = split(";",$read file[$k]);
    >
    > $date = date("Ymd");
    >[/color]

    $c = date("Ymd", strtotime($fiel d[0]));
    [color=blue]
    > if ($c >= $date) {[/color]

    Hi Bill,

    Much easier - use strtotime(). See above.

    HTH;
    JOn

    Comment

    Working...