| Author |
Message |
rogue3 Regular


Joined: Jul 02, 2009 Posts: 63
|
Posted:
Thu Sep 24, 2009 12:57 pm |
|
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? |
|
|
|
 |
Palbin Site Admin

Joined: Mar 30, 2006 Posts: 2456 Location: Pittsburgh, Pennsylvania
|
Posted:
Thu Sep 24, 2009 1:10 pm |
|
date() uses timestamps not formatted date strings.
|
|
|
|
 |
rogue3 Regular


Joined: Jul 02, 2009 Posts: 63
|
Posted:
Thu Sep 24, 2009 1:54 pm |
|
This is the same format that was used in my other sections. Why would it not be working here? |
|
|
|
 |
eldorado Involved


Joined: Sep 10, 2008 Posts: 414 Location: France,Translator
|
Posted:
Thu Sep 24, 2009 2:14 pm |
|
| rogue3 wrote: | | December 31, 1969 |
if the date() has uncorresponding arguments it returns the 0 value wich corresponds to 1st January 1970 (unix date)
I suggest you look at this
or the php manual |
|
|
|
 |
montego Site Admin

Joined: Aug 29, 2004 Posts: 9136 Location: Arizona
|
Posted:
Thu Sep 24, 2009 5:53 pm |
|
Let us not be mixing MySQL DATE formats with PHP. You may want to read this:
|
|
|
|
 |
rogue3 Regular


Joined: Jul 02, 2009 Posts: 63
|
Posted:
Thu Sep 24, 2009 5:56 pm |
|
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 Site Admin

Joined: Aug 29, 2004 Posts: 9136 Location: Arizona
|
Posted:
Thu Sep 24, 2009 5:59 pm |
|
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 Regular


Joined: Jul 02, 2009 Posts: 63
|
Posted:
Thu Sep 24, 2009 6:04 pm |
|
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 Site Admin

Joined: Aug 29, 2004 Posts: 9136 Location: Arizona
|
Posted:
Thu Sep 24, 2009 6:08 pm |
|
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. |
|
|
|
 |
|
|
|
|