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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Converting Date Format with PHP

    So I'm trying to convert date from Yr-m-d to M-D-y. I did some research and come up with the code below. Problem is, it's posting the date as 01-01-1970, which is not the date in the database. I can't figure out what I'm doing. THoughts?

    PHP Code:
    $result mysql_query("SELECT * FROM `calendar` ORDER BY airdate") or die($myQuery."<br/><br/>".mysql_error());
    $given = ['airdate'];
    $parseit date("m-d-Y"strtotime($given));

    while(
    $row mysql_fetch_array($result)){
    $program $row['ID'];
    echo 
    "<h2>" $row['program'] . "</h2>";
    echo 
    "<h3>" $parseit "</h3>";
    echo 
    "<p>" $row['description'] . "</p>";
    echo 
    "<p><strong> On-Air: </strong>" .$row['production'] . "<br />";
    echo 
    "<p> <strong>Promotion: </strong> " .$row['promotion'] . "<br />";
    echo 
    "<p><strong> Online: </strong>" .$row['web'] . "<br />";
    echo 
    "<p><strong>Community: </strong>" .$row['community'] . "<br />";
    echo 
    '<p><a href="edit.php?id=' $row['ID'] . '">Edit</a></p>';
    }
    require_once(
    "db_connx_close.php");
    ?> 

  • #2
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    This means that the variable $given is empty. If you give strtotime an empty variable, it resolves to 1970-1-1 which is the start of the unix timestamp.

    There is something wrong with your code:

    PHP Code:
    $given = ['airdate'];  //What is this??? 
    You should probably have the $given in the while loop as so:

    while($row = mysql_fetch_array($result)){
    $program = $row['ID'];

    //Changes
    $given = $row['airdate'];
    $parseit = date("m-d-Y", strtotime($given));
    //End fo addition changes
    echo "<h2>" . $row['program'] . "</h2>";
    echo "<h3>" . $parseit . "</h3>";
    echo "<p>" . $row['description'] . "</p>";
    echo "<p><strong> On-Air: </strong>" .$row['production'] . "<br />";
    echo "<p> <strong>Promotion: </strong> " .$row['promotion'] . "<br />";
    echo "<p><strong> Online: </strong>" .$row['web'] . "<br />";
    echo "<p><strong>Community: </strong>" .$row['community'] . "<br />";
    echo '<p><a href="edit.php?id=' . $row['ID'] . '">Edit</a></p>';
    }


  •  

    Posting Permissions

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