SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Smile Changing Date Format, Possible?

    Currently I offer the customer to view an upcoming calendar. This is done by selecting the desired date from a drop menu. Seen here:
    PHP Code:
    while ($list mysql_fetch_array($soups)) {
    $date $list["Day"];
    echo(
    "<option value='$date'>$date</option>"); 
    The value "Day" is stored in the database as YYYY-MM-DD; nothing abnormal. However, this confuses customers and I can see why. Is this possible to change to a readable format?

    After putting some thought into it, I would need to disect the value and piece it together in a new order with 3 variables, right? I just can't seem to get it to work.

    Thanks guys!
    TAKE A WALK OUTSIDE YOUR MIND.

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    date
    (PHP 3, PHP 4 )

    date -- Format a local time/date
    Description
    string date ( string format [, int timestamp])


    Returns a string formatted according to the given format string using the given integer timestamp or the current local time if no timestamp is given.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not sure if this is what you were looking for, but here's some code that might help:
    PHP Code:
    <?php
    while ($list mysql_fetch_array($soups)) {
    $date $list["Day"];
    list (
    $year$month$day) = split ('[/.-]'$date);
    if(
    $month==01) {
    $month "January";
    } elseif(
    $month==02) {
    $month "Febuary";
    } elseif(
    $month==03) {
    $month "March";
    } elseif(
    $month==04) {
    $month "April";
    } elseif(
    $month==05) {
    $month "May";
    } elseif(
    $month==06) {
    $month "June";
    } elseif(
    $month==07) {
    $month "July";
    } elseif(
    $month==08) {
    $month "August";
    } elseif(
    $month==09) {
    $month "September";
    } elseif(
    $month==10) {
    $month "October";
    } elseif(
    $month==11) {
    $month "November";
    } elseif(
    $month==12) {
    $month "December";
    }
    $date $month.' '.$day.', '.$year;
    echo(
    "<option value='$date'>$date</option>" ); 
    ?>

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW, why are customers confused by YYYY-MM-DD?
    That's the ISO standard for dates
    http://www.cl.cam.ac.uk/~mgk25/iso-time.html

  5. #5
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I read that before, and it didn't really help. Could you please explain?
    TAKE A WALK OUTSIDE YOUR MIND.

  6. #6
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Example:
    echo "<option value='$date'>" .date("l F j Y", $date) ."</option>";
    should print out
    <option value="2003-05-30">Friday May 30 2003</option>

    Edit: Forgot... $date can't be a string, must be a timestamp...
    Correct code
    list($y, $m, $d) = explode("-", $date);
    echo "<option value='$date'>" .date("l F j Y", mktime(0, 0, 0, $m, $d, $y)) ."</option>";
    Last edited by jofa; May 29, 2003 at 19:29.

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Learn something new every day. I didn't know you could do that jofa? Thanks for that!

  8. #8
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I live in Canada, and doing a lot of work in BOTH USA and Canada... I find it VERY annoying to distinguish whether the date is MM/DD or DD/MM... as they are in different orders in the different countries... I wish everyone would just use naming in the date... heh
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  9. #9
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WhSox21
    Learn something new every day. ...
    Of course, if you want the month names in another language than English, I guess an array of translations is the only way to do it?

    Comment: All those if...elseif? Why not use switch?

  10. #10
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KandieMan101
    ... I wish everyone would just use naming in the date... heh
    In French, English - or Inuktituk?

  11. #11
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    date('l F j Y'strtotime($date)); 
    strtotime() handles a LOT of date-formats.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  12. #12
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jofa
    In French, English - or Inuktituk?
    In whatever language the rest of the text on the page is in?
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  13. #13
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys! Worked perfectly.
    TAKE A WALK OUTSIDE YOUR MIND.

  14. #14
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great to hear!
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter


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
  •