SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 29 of 29
  1. #26
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    uk
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works if you set the variable to contain one date only as you did: $product['departuredate'] = '10-05-2010'; but the variable contains a set of dates so it still prints them as this format
    --24/04/2010--17/04/2010--19/04/2010

    I am not sure if its the dash at the beginning ("-", that is confusing it? I tried removing it but it generates a syntax error.

    may be we need a way to get rid of the dashes. not sure?

  2. #27
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    See... you can't tell me it contains "10-05-2010" if it actually contains dates in "10/05/2010"... of course the code doesn't work right when you change the precondition...

    Quote Originally Posted by hm9
    I am not sure if its the dash at the beginning ("-", that is confusing it? I tried removing it but it generates a syntax error.
    Look up the split function in the PHP manual and it'll be clear... you don't learn if you don't try to understand the code you're looking at.

  3. #28
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    uk
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry should have made it clear that it stores a set of dates in the array
    I understand how the split works with just one date e.g. '10-05-2010' but with an array of dates like 24/04/2010--26/04/2010--10-05-2010 etc its more difficult. which is what $product['departuredate'] holds




    The examples shown on tutorials are simpler and basic, could nt find any tutorials that shows how to break the dates etc ?

  4. #29
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    uk
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I solved the issue now:




    $date1 = $product['departuredate'];
    list($day, $month, $year) = split( '[/.-]', $date1);
    $date3 = "$year-$month-$day<br />\n";

    echo $date3;

    This prints the correct dates and in the correct format

    2010-05-12
    2010-04-10
    etc


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
  •