www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-05-2009, 02:19 AM
    m5884 m5884 is offline
    Registered User
     
    Join Date: Aug 2009
    Posts: 11
    Unhappy Date not displaying properly

    Hi, this might a very newbie question, but my date isn't displaying properly and I do not know why!!

    I have something like this:
    Code:
    <?php
    $sql = "SELECT * FROM db_table WHERE Bpublished = '1' AND Bcater='$passed_cater' ORDER BY Bid DESC LIMIT $ppage, $limit";
    $res = mysql_query($sql,$conn); 
    	while ($row_blog = mysql_fetch_array($res)) {							
    		echo date('d M Y', $row_blog['Bdate']); 
    	};
    ?>
    And all the entries echo this - 31 Dec 1969

    I've tried variations of it, such as
    Code:
    echo date('r', $row_blog['Bdate']);
    or
    Code:
    echo date('m-d-y H:i:s', $row_blog['Bdate']);
    And they all produce variations of 31 December 1969!!

    I don't have any entries with that date, so why is it doing that??

    I'm very frustrated and I can't seem to get any answers in google!!

    Please help!!
    Reply With Quote
      #2  
    Old 11-05-2009, 03:01 AM
    kaafmim's Avatar
    kaafmim kaafmim is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 32
    You are facing a funny problem! The first defined date is January 1, 1970. So what you receive, the day before the first defined date in php, means that the value of $row_blog['Bdate'] is -1 .

    This means that mysql is returning an error while connecting the database, reading the entry, or something else. The sure thing is that the problem is in your database query, and not the date function and format.

    Good luck!
    Reply With Quote
      #3  
    Old 11-05-2009, 03:30 AM
    NogDog's Avatar
    NogDog NogDog is offline
    High Energy Magic Dept.
     
    Join Date: Aug 2004
    Location: Ankh-Morpork
    Posts: 13,668
    More likely you are getting an empty value, a zero, or a string that evaluates as zero when converted to an integer, and your server's time zone is somewhere west of the Prime Meridian. Unless the value being returned by your query is a UNIX timestamp integer, then it is not ready to be used as the 2nd parameter for date(). You may need to convert it with something like strtotime() first:
    PHP Code:
    echo date('d M Y', strtotime($row_blog['Bdate']));
    __________________
    "That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett
    freelancer.internet.com
    Email me
    Reply With Quote
      #4  
    Old 11-05-2009, 07:09 PM
    m5884 m5884 is offline
    Registered User
     
    Join Date: Aug 2009
    Posts: 11
    Quote:
    Originally Posted by kaafmim View Post
    You are facing a funny problem! The first defined date is January 1, 1970. So what you receive, the day before the first defined date in php, means that the value of $row_blog['Bdate'] is -1 .

    This means that mysql is returning an error while connecting the database, reading the entry, or something else. The sure thing is that the problem is in your database query, and not the date function and format.

    Good luck!
    Hi kaafmim! Thank you for your reply. Is there anyway I could check for this error?

    Still frustrated! hehe
    Reply With Quote
      #5  
    Old 11-05-2009, 07:12 PM
    m5884 m5884 is offline
    Registered User
     
    Join Date: Aug 2009
    Posts: 11
    Quote:
    Originally Posted by NogDog View Post
    More likely you are getting an empty value, a zero, or a string that evaluates as zero when converted to an integer, and your server's time zone is somewhere west of the Prime Meridian. Unless the value being returned by your query is a UNIX timestamp integer, then it is not ready to be used as the 2nd parameter for date(). You may need to convert it with something like strtotime() first:
    PHP Code:
    echo date('d M Y', strtotime($row_blog['Bdate']));
    Hi NogDog! (interesting name btw )

    I tried strtotime() but it returns the same value. I think my time zone setup for mySQL is correct. Because when I echo the actual date row, I get the right dates, such as 2009-11-05. It is only when I try to apply a date() format to it that it seem to stuff up!
    Reply With Quote
      #6  
    Old 11-05-2009, 07:50 PM
    NogDog's Avatar
    NogDog NogDog is offline
    High Energy Magic Dept.
     
    Join Date: Aug 2004
    Location: Ankh-Morpork
    Posts: 13,668
    What do you get if you just echo out $row_blog['Bdate'] instead of using any of the date functions? (In other words, we need to find out what the original value is that you're using.)
    __________________
    "That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett
    freelancer.internet.com
    Email me
    Reply With Quote
      #7  
    Old 11-08-2009, 06:49 PM
    m5884 m5884 is offline
    Registered User
     
    Join Date: Aug 2009
    Posts: 11
    Quote:
    Originally Posted by NogDog View Post
    What do you get if you just echo out $row_blog['Bdate'] instead of using any of the date functions? (In other words, we need to find out what the original value is that you're using.)
    I get the correct date, such as: 2009-11-02
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 05:12 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.