SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: date()

  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Virginina
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date()

    $date = date("m/d/Y", $date_entered);

    Is giving me

    12/31/1969

    WHY is this happening!!!

    I need it to stay on the real date it was posted forever.

    Im trying to write a news system!

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elementskater255
    $date = date("m/d/Y", $date_entered);

    Is giving me

    12/31/1969

    WHY is this happening!!!

    I need it to stay on the real date it was posted forever.

    Im trying to write a news system!
    check out your db input form variables...
    maybe u replaced the day with month!

  3. #3
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Virginina
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whaaa?

  4. #4
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly is in $date_entered ? To make sure, try echo $date_entered; .

  5. #5
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Virginina
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmmm, didnt do anything? Its the name of my table, I tried setting it to just date_entered but nothing happened. Heres the WHOLE view.php:

    PHP Code:
    <htmL>
    <head>
    <title>News</title>
    </head>
    <body>
    <?php
    ini_set 
    ('display_errors'1);
    error_reporting (E_ALL & ~E_NOTICE);
    include(
    'config.php');
    if (
    $dbc = @mysql_connect ($db_host$db_user$db_pass)) {

        if (!@
    mysql_select_db ($db_name)) {
            die (
    '<p>Could not select the database because: <b>' mysql_error() . '</b></p>');
        }

    } else {
        die (
    '<p>Could not connect to MySQL because: <b>' mysql_error() . '</b></p>');
    }
    print 
    "<center><font face='arial' size='2'><a href=index.php>Home</a>&nbsp; |&nbsp;&nbsp;<a href=add_entry.php>Add a News Entry</a>&nbsp; |&nbsp;&nbsp;<a href=stats.php>Site Stats</a></font></center><br><br><center><font size=4 face=arial><b>NEWS</b></font></center>";
    $query 'SELECT * FROM blog_entries ORDER BY date_entered DESC';
    $date date("m/d/Y"$date_entered);
    if (
    $r mysql_query ($query)) {


        while (
    $row mysql_fetch_array ($r)) {
            print 
    "<font face='arial' size='2'>Title:&nbsp;&nbsp;</font><b><font face='arial' size='4'>{$row['title']}</b></font><br>
            <font face='arial' size='2'>Date:&nbsp;&nbsp;</font><font face='arial' size='-1'>
    $date</font><br><br>
                    <font face='arial' size='2'>News:&nbsp;&nbsp;</font><font face='arial' size='-1'>
    {$row['entry']}</font><br>
            <font face='arial' size='-1'><a href=\"edit_entry.php?id=
    {$row['blog_id']}\">Edit</a>
            <a href=\"delete_entry.php?id=
    {$row['blog_id']}\">Delete</a></font>
            </p><br><br>"
    ;
        }

    } else {
        die (
    '<p>Could not retrieve the data because: <b>' mysql_error() . "</b>. The query was $query.</p>");
    }

    mysql_close();

    ?>
    </body>
    </html>

  6. #6
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How is the date stored in the DB? If it's an integer try this:

    PHP Code:
    <htmL>
    <head>
    <title>News</title>
    </head>
    <body>
    <?php
    ini_set 
    ('display_errors'1);
    error_reporting (E_ALL & ~E_NOTICE);
    include(
    'config.php');
    if (
    $dbc = @mysql_connect ($db_host$db_user$db_pass)) {

        if (!@
    mysql_select_db ($db_name)) {
            die (
    '<p>Could not select the database because: <b>' mysql_error() . '</b></p>');
        }

    } else {
        die (
    '<p>Could not connect to MySQL because: <b>' mysql_error() . '</b></p>');
    }
    print 
    "<center><font face='arial' size='2'><a href=index.php>Home</a>&nbsp; |&nbsp;&nbsp;<a href=add_entry.php>Add a News Entry</a>&nbsp; |&nbsp;&nbsp;<a href=stats.php>Site Stats</a></font></center><br><br><center><font size=4 face=arial><b>NEWS</b></font></center>";
    $query 'SELECT * FROM blog_entries ORDER BY date_entered DESC';
    if (
    $r mysql_query ($query)) {


        while (
    $row mysql_fetch_array ($r)) {
                             
    $date date("m/d/Y"$row['date_entered']);
            print 
    "<font face='arial' size='2'>Title:&nbsp;&nbsp;</font><b><font face='arial' size='4'>{$row['title']}</b></font><br>
            <font face='arial' size='2'>Date:&nbsp;&nbsp;</font><font face='arial' size='-1'>
    $date</font><br><br>
                    <font face='arial' size='2'>News:&nbsp;&nbsp;</font><font face='arial' size='-1'>
    {$row['entry']}</font><br>
            <font face='arial' size='-1'><a href=\"edit_entry.php?id=
    {$row['blog_id']}\">Edit</a>
            <a href=\"delete_entry.php?id=
    {$row['blog_id']}\">Delete</a></font>
            </p><br><br>"
    ;
        }

    } else {
        die (
    '<p>Could not retrieve the data because: <b>' mysql_error() . "</b>. The query was $query.</p>");
    }

    mysql_close();

    ?>
    </body>
    </html>
    If not, try replacing this line:
    PHP Code:
    $date date("m/d/Y"$row['date_entered']); 
    with this:
    PHP Code:
    $date date("m/d/Y",strtotime$row['date_entered'])); 

  7. #7
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Virginina
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YES that 2nd one worked THANKS

  8. #8
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now let's also apply several best practices and use
    PHP Code:
    $date date('m/d/Y'strtotime($row['date_entered'])); 

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when input...
    PHP Code:
    list($d$m$Y) = date(mktime(date(H)));
    $date explode("/"$d/$m/$Y); 
    when output
    PHP Code:
    echo implode("/"$date); 
    cheers

  10. #10
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by reminder
    PHP Code:
    list($d$m$Y) = date(mktime(date(H))); 
    So you use date('H'); to get the current hour from UNIX time, you use mktime() to get the UNIX time based on the current hour and then you calculate something based on that UNIX time? I say something because you can not omit the "format" value from calls to date() ( www.php.net/date ) .
    Is that really what you want to do?


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
  •