Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
rogue3
Regular
Regular


Joined: Jul 02, 2009
Posts: 63

PostPosted: Thu Sep 24, 2009 12:57 pm Reply with quote

I'm having a devil of a time getting the date to pull correctly from my database. All it does is pull December 31, 1969

I cannot get it to pull the date that is in the field in the database.

The field type is 'date' and name is 'date' and it is stored in this format: 2009-05-24

Here is the function code:

Code:
   while($myrow = $db->sql_fetchrow($result)) {

    $title = stripslashes(check_html($myrow["title"], "nohtml"));
    $id = intval($myrow['id']);
                $date = $myrow['date'];
   $fdate = date('F j, Y', $date);


What am I missing here?
 
View user's profile Send private message
Palbin
Site Admin


Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Thu Sep 24, 2009 1:10 pm Reply with quote

date() uses timestamps not formatted date strings.
Only registered users can see links on this board! Get registered or login!

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
rogue3
PostPosted: Thu Sep 24, 2009 1:54 pm Reply with quote

This is the same format that was used in my other sections. Why would it not be working here?
 
eldorado
Involved
Involved


Joined: Sep 10, 2008
Posts: 424
Location: France,Translator

PostPosted: Thu Sep 24, 2009 2:14 pm Reply with quote

rogue3 wrote:
December 31, 1969

if the date() has uncorresponding arguments it returns the 0 value wich corresponds to 1st January 1970 Smile (unix date)
I suggest you look at this Only registered users can see links on this board! Get registered or login!
or the php manual Only registered users can see links on this board! Get registered or login!

_________________
Only registered users can see links on this board! Get registered or login! (My RN site)- Only registered users can see links on this board! Get registered or login!(cod4 clan) - Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website MSN Messenger
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9453
Location: Arizona

PostPosted: Thu Sep 24, 2009 5:53 pm Reply with quote

Let us not be mixing MySQL DATE formats with PHP. You may want to read this:
Only registered users can see links on this board! Get registered or login!

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
rogue3
PostPosted: Thu Sep 24, 2009 5:56 pm Reply with quote

The dates that are in the fields in the database are all different. For some reason it does not pull the date from the field, but instead puts the same date for all of them.
 
montego
PostPosted: Thu Sep 24, 2009 5:59 pm Reply with quote

What do you get when you just echo out the $date field.

BTW, what the others were trying to say is that you cannot use the PHP date() function on anything other than a unix time stamp.
 
rogue3
PostPosted: Thu Sep 24, 2009 6:04 pm Reply with quote

OK, I SWEAR I tried this before, but now it is working. Good grief.

Here's the code that is now working:

Code:
         $date = $myrow['date'];

    $year = substr($date,0,4);
      $month = substr($date,5,2);
     $day = substr($date,8,2);
     $fdate = date("F jS Y",mktime (0,0,0,$month,$day,$year));
 
montego
PostPosted: Thu Sep 24, 2009 6:08 pm Reply with quote

Yes, what you posted works because it takes the "YYYY-MM-DD" format and "converts" it to a datetime stamp which then the date() function can format.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©