Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Pulling DATE from database using MySQL and PHP
Old 08-04-2011, 03:31 PM Pulling DATE from database using MySQL and PHP
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Hi Guys,

I have a little problem with pulling a DATE from a database. Below is my code for the page I am trying to create.

I have in the database a date - 2011-07-27 and I am trying to set the dates into an array so that I can organise dates into YEAR and MONTH.

Now, I don't know if the database is the problem. The field is set to DATE.

// Add each entry to the $data array, sorted by Year and Month
while($row = $result->fetch_assoc())
{
$year = date('Y', $row['articleDate']);
$month = date('m', $row['articleDate']);

$data[$year][$month][] = $row;
}
$result->free();

The above code returns 1970 for year and 01 for month.

Help Please

Thank you
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-04-2011, 04:10 PM Re: Pulling DATE from database using MySQL and PHP
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Live example: http://www.klsactivelifestyle.co.uk/archive.php
feraira is offline
Reply With Quote
View Public Profile
 
Old 08-04-2011, 04:31 PM Re: Pulling DATE from database using MySQL and PHP
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
date expects the second parameter to be a timestamp (integer), not a mysql formatted date. Use strtotime to convert the date to a timestamp first and then format it with date.

PHP Code:
while($row $result->fetch_assoc())
{
     
$ts strtotime($row['articleDate']);
     
$year date('Y'$ts);
     
$month date('m'$ts);
/* 
.
.
.
*/ 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-05-2011, 02:01 PM Re: Pulling DATE from database using MySQL and PHP
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
That's worked perfectly! Thanks.

Updated dates: www.klsactivelifestyle.co.uk/archive.php
feraira is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Pulling DATE from database using MySQL and PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.42308 seconds with 12 queries