Professional Web Applications Themes

Can I display a month from a number in a csv file? - PHP Development

Greetings from a second day newbie to php. I think I have figured out a way to explode a field in a csv file (like 11-08-03) and implode it as 031108 and then compare it to the current date(ymd) to display data after the current date. What I would like to now do is use the 11 and display Nov. Can anybody help or point me in the right direction? Thanks. Bill...

  1. #1

    Default Can I display a month from a number in a csv file?

    Greetings from a second day newbie to php.

    I think I have figured out a way to explode a field in a csv file (like
    11-08-03) and implode it as 031108 and then compare it to the current
    date(ymd) to display data after the current date. What I would like to now
    do is use the 11 and display Nov. Can anybody help or point me in the right
    direction?

    Thanks.
    Bill


    The Biscuit Eater Guest

  2. #2

    Default Re: Can I display a month from a number in a csv file?

    I noticed that Message-ID: <7eUnb.43950$9E1.180122attbi_s52> from The
    Biscuit Eater contained the following:
    >Greetings from a second day newbie to php.
    >
    >I think I have figured out a way to explode a field in a csv file (like
    >11-08-03) and implode it as 031108 and then compare it to the current
    >date(ymd) to display data after the current date. What I would like to now
    >do is use the 11 and display Nov. Can anybody help or point me in the right
    >direction?
    Any particular reason why you're not using a database for this?


    --
    Geoff Berrow
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs [url]http://www.ckdog.co.uk/rfdmaker/[/url]
    Geoff Berrow Guest

  3. #3

    Default Re: Can I display a month from a number in a csv file?

    The Biscuit Eater wrote:
    > Greetings from a second day newbie to php.
    >
    > I think I have figured out a way to explode a field in a csv file (like
    > 11-08-03) and implode it as 031108 and then compare it to the current
    > date(ymd) to display data after the current date. What I would like to now
    > do is use the 11 and display Nov. Can anybody help or point me in the right
    > direction?
    My first idea (probably not the best) was:

    make an array and select from that:

    <?php
    $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

    // do whatever you need, including
    $month = 11;

    // and, after being real sure 1 <= $month <= 12
    echo $months[$month-1];
    ?>

    --
    I have a spam filter working.
    To mail me include "urkxvq" (with or without the quotes)
    in the subject line, or your mail will be ruthlessly discarded.
    Pedro Guest

  4. #4

    Default Re: Can I display a month from a number in a csv file? - got it


    "Pedro" <hexkidhotpop.com> wrote in message
    news:bnpg0p$148ntn$1ID-203069.news.uni-berlin.de...
    > My first idea (probably not the best) was:
    >
    > make an array and select from that:
    >
    > <?php
    > $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
    > 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    >
    > // do whatever you need, including
    > $month = 11;
    >
    > // and, after being real sure 1 <= $month <= 12
    > echo $months[$month-1];
    > ?>
    >
    Thanks, that was where I was heading when, while driving home this evening,
    I came up with something that apparently works just fine. I can now pull the
    next event or all events from a csv file using the following:

    <?

    $readfile = file("events.txt");


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

    $date = date("Ymd");

    $piece = explode("-", $field[0]);
    $array = array($piece[2], $piece[0], $piece[1]);
    $c = implode("", $array);
    $d = date("jS",mktime(0,0,0,$piece[0],$piece[1],$piece[2]));
    $m = date("M",mktime(0,0,0,$piece[0],$piece[1],$piece[2]));

    if ($c >= $date) {

    print ("<a class=\"noUL\" href=\"javascript:void(0);\"
    onclick=\"window.open('events/$field[0].htm', 'NextEvent', 'scrollbars=yes,
    resizable=yes, height=600, width=650')\">$m $d - $field[1]</A>");

    exit;
    }
    }

    ?>

    The csv is setup like:

    11-06-2003;Beat the Pro;Individual play;tee choice;8:30 AM Shotgun
    01-10-2004;Twister;(Scramble-Stableford);Four man teams (white tees)


    The Biscuit Eater Guest

  5. #5

    Default Re: Can I display a month from a number in a csv file? - got it

    Carved in mystic runes upon the very living rock, the last words of The
    Biscuit Eater of comp.lang.php make plain:
    >
    > "Pedro" <hexkidhotpop.com> wrote in message
    > news:bnpg0p$148ntn$1ID-203069.news.uni-berlin.de...
    >
    >> My first idea (probably not the best) was:
    >>
    >> make an array and select from that:
    >>
    >> <?php
    >> $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
    >> 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    >>
    >> // do whatever you need, including
    >> $month = 11;
    >>
    >> // and, after being real sure 1 <= $month <= 12
    >> echo $months[$month-1];
    >> ?>
    >>
    >
    > Thanks, that was where I was heading when, while driving home this
    > evening, I came up with something that apparently works just fine. I
    > can now pull the next event or all events from a csv file using the
    > following:
    Great googly-moogly! Now that's newbie code if I ever saw it! :)

    $thefile = file("events.txt");
    while (list(,$record) = each($thefile)) {
    $fields = split(";", $record);
    $stamp = strtotime("$field[0] 00:00:00");
    if $stamp > time() {
    [do stuff]
    }
    }

    And you can use the date() function on $stamp to get whatever formatted
    date info you want. strtotime() is your friend.

    --
    Alan Little
    Phorm PHP Form Processor
    [url]http://www.phorm.com/[/url]
    Alan Little Guest

  6. #6

    Default Re: Can I display a month from a number in a csv file? - THANKS!

    I want to thank Alan and Jon for sending me in the right direction. With the
    following I can pull the next golf tournament from a csv file and display a
    link to a popup for more information - and in addition, display the days
    until and sign up deadline. Thanks again for your help.

    Seems to work nicely... [url]http://www.mgagcai.org/[/url]

    <?
    $thefile = file("events.csv");
    while (list(,$record) = each($thefile)) {
    $field = split(";", $record);
    $stamp = strtotime("$field[0]");
    if (ceil(($stamp - time())/86400) >= 0) {
    echo "<a href=\"javascript:void(0);\" onclick=\"window.open('/"
    ,date("Ymd", strtotime ($field[0])), ".html', 'NextEvent', 'scrollbars=yes,
    resizable=yes, height=600, width=650')\">", date("M jS", strtotime
    ($field[0])), " - $field[1]</A><br />";
    echo "<span class=\"sans\">";
    if (ceil(($stamp - time())/86400) > 7) {
    echo ceil(($stamp - time())/86400), " days away";
    } else if (ceil(($stamp - time())/86400) >= 4) {
    echo "Only ", ceil(($stamp - time())/86400), " days away. Sign up by
    Wednesday evening.";
    } else if (ceil(($stamp - time())/86400) == 3) {
    echo "Only ", ceil(($stamp - time())/86400), " days away. Sign up by
    this evening.";
    } else if (ceil(($stamp - time())/86400) == 2) {
    echo "Only ", ceil(($stamp - time())/86400), " days away. Too late to
    sign up.";
    } else if (ceil(($stamp - time())/86400) == 1) {
    echo "Only ", ceil(($stamp - time())/86400), " day away. Too late to
    sign up.";
    } else {
    echo "Event is today";
    }
    echo "</span>";
    exit;
    }
    }
    ?>

    ---
    Bill "Chessie" Hayes
    [url]http://www.billhayes.us[/url]
    ICQ#: 9635690

    Bakers trade bread recipes on a knead to know basis.

    "Alan Little" <alann-o-s-p-a-m-phorm.com> wrote in message
    news:Xns942457892662Dalanphormcom216.196.97.132.. .
    > Carved in mystic runes upon the very living rock, the last words of The
    > Biscuit Eater of comp.lang.php make plain:
    >
    > >
    > > "Pedro" <hexkidhotpop.com> wrote in message
    > > news:bnpg0p$148ntn$1ID-203069.news.uni-berlin.de...
    > >
    > >> My first idea (probably not the best) was:
    > >>
    > >> make an array and select from that:
    > >>
    > >> <?php
    > >> $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
    > >> 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    > >>
    > >> // do whatever you need, including
    > >> $month = 11;
    > >>
    > >> // and, after being real sure 1 <= $month <= 12
    > >> echo $months[$month-1];
    > >> ?>
    > >>
    > >
    > > Thanks, that was where I was heading when, while driving home this
    > > evening, I came up with something that apparently works just fine. I
    > > can now pull the next event or all events from a csv file using the
    > > following:
    >
    > Great googly-moogly! Now that's newbie code if I ever saw it! :)
    >
    > $thefile = file("events.txt");
    > while (list(,$record) = each($thefile)) {
    > $fields = split(";", $record);
    > $stamp = strtotime("$field[0] 00:00:00");
    > if $stamp > time() {
    > [do stuff]
    > }
    > }
    >
    > And you can use the date() function on $stamp to get whatever formatted
    > date info you want. strtotime() is your friend.
    >
    > --
    > Alan Little
    > Phorm PHP Form Processor
    > [url]http://www.phorm.com/[/url]

    The Biscuit Eater Guest

Similar Threads

  1. Getting the month by Number
    By silstorm in forum Coldfusion - Advanced Techniques
    Replies: 3
    Last Post: July 5th, 07:36 AM
  2. change month number to name
    By sattman in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: October 8th, 12:37 AM
  3. display records according to month and year
    By thnguyen in forum Macromedia ColdFusion
    Replies: 8
    Last Post: June 2nd, 09:14 PM
  4. Display x number of records
    By Dave Karmens in forum ASP Database
    Replies: 5
    Last Post: April 19th, 04:49 AM
  5. Display month and days with results
    By Andy Hassall in forum PHP Development
    Replies: 0
    Last Post: August 17th, 05:10 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139