Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trying to change the date format!

    Sorry that I keep posting this same script!

    Im just trying to make the dates of the shows be formatted as "June 10th" for example.

    I have searched threads on here and found this thread...
    Date Conversion Troubles (newb)

    I tried using the solution by inserting $date = date('F d, Y', strtotime($date)); and then using $date as the variable to echo. However all my dates then for some obscure reason become May 4th...

    Anyone know what I'm doing wrong? My script is functional but this will make it much more prettiful



    <?php
    require ('../../dryriseconnect.php');

    //select future show dates from db
    $result = mysql_query('SELECT * FROM shows WHERE showdate > DATE_SUB(CURDATE(), INTERVAL 0 DAY) ORDER BY showdate ASC',$db) or die ('Unable to perform selectquery. Exit script');

    //if no rows returned, then say so

    if (mysql_num_rows($result) < 1){
    echo 'No dates to display.';
    } else {

    $last_month = "";

    while ($row=mysql_fetch_assoc($result))
    {

    if($last_month != date("F", strtotime($row['showdate'])))
    {
    echo '<p class="heading">' . date("F", strtotime($row['showdate'])) . '<p>';
    }

    echo '<p class="main">' . $row['showdate'] . ' - ' . $row['venue'] . ', ' . $row['location'] . "\n" . '</span><br>' . "\n" .
    '<span class="main">' . $row['showinfo'] . '</span>' . "\n";

    $last_month = date("F", strtotime($row['showdate']));

    }
    }
    ?>

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    How are your dates stored in you database?

    Did you add all of those dates you tested on the 4th May? It sounds like you added them through phpmyadmin and didn't remove the NOW() function when you were adding dates, 'cos I can't see anything wrong with your code.

    If you have to go through all the dates and redo them, I would recommend storing them in the database as UNIX_TIMESTAMP's and then removing all the strtotime() functions you have everywhere.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't think it's to do with the database. The dates are in DATE format and manually inserted.

    The dates are OK at the moment, just in the wrong format... heres the code working:

    http://www.suicidenotesmusic.net/dryrise/shows.php

    I just want to change them. The code I showed didnt include the alteration which made it go wrong, i had simply added one line of code

    $date = date('F d, Y', strtotime($date));

    and then instead of echoing $row['showdate'] i echoed $date

    Then it all went horrible wrong!

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by dysfunctionGazz
    $date = date('F d, Y', strtotime($date));
    That will stuff it up because... $date is being used twice in that function, use a different variable name...

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you just trying to change the format of the output date? Or is something wrong with the date output its self?

    Changing date format: http://us2.php.net/function.date

    If not, make sure that the lines of code you added are inside the while, otherwise it will be outputting a NULL date, and date() will just output the current date.
    "$question = ( to() ) ? be() : ~be();"

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wicked. Thats it.

    I had the bit of code to reformat the date outside the WHILE and hence why it kept giving the shows the wrong date.

    Thanks!

  • #7
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glad to help, and the page looks good. Just be sure to change the title .
    "$question = ( to() ) ? be() : ~be();"


  •  

    Posting Permissions

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