General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 3rd, 2003, 04:54 PM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
Date() not displaying all information

I have my site displaying times when news articles were edited last (if they were edited). I want it to show the date and time when it was edited However it is only showing the date and for time it is only showing 00:00. Here is the code:
PHP Code:
 $query=mysql_query("SELECT*,UNIX_TIMESTAMP(editing_date) FROM article");
$result=mysql_fetch_array($query);
$edited=date("m/d/Y H:i"strtotime($result['editing_date']));
echo 
$edited
__________________
CHornJr
"One day I'll know what I am doing"
My Blog
Suanhacky Lodge #49
Rebel Squadrons

Reply With Quote
  #2  
Old October 3rd, 2003, 04:58 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
My guess is either that your editing_date field is a date rather than a datetime field or that you're inserting dates with no time values into it if it's a datetime field. Select just the editing_date with no formatting and see what you get.

Reply With Quote
  #3  
Old October 3rd, 2003, 05:30 PM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
My editing_date field is a timestamp field

Reply With Quote
  #4  
Old October 3rd, 2003, 05:39 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
This has bitten me in the bum a number of times. You need to give your field an alias:

PHP Code:
 $query=mysql_query("SELECT*,UNIX_TIMESTAMP(editing_date) as editing_date FROM article"); 


Wrapping a function around it effectively changes the column name for the purposes of the output.

Reply With Quote
  #5  
Old October 4th, 2003, 01:41 AM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
That did not seem to fix the problem completely because it is now showing 13:00 instead of the correct time.

I have attached the actual file just incase

Last edited by CHornJr : October 4th, 2003 at 05:52 PM.

Reply With Quote
  #6  
Old October 4th, 2003, 08:20 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
In the following code (starting at line 39):

PHP Code:
 $posted=date("m/d/Y",strtotime($article['posting_date']));
                                                                                                             
$editdate=date("m/d/Y H:i",strtotime($article['editing_date'])); 


you're invoking $article, which is the variable you're putting $news['article_text'] into, when it seems you should be invoking $news. Also, in your query, you'll need to give an alias to the posting_date field as well.

Reply With Quote
  #7  
Old October 4th, 2003, 05:51 PM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
Thank you for pointing out the call to the wrong variable. However, it is now showing the posting date as 12/31/1969 and the editing date & time as 12/31/1969 18:59.

I have attached the updated file
Attached Files
File Type: zip chornjr_date()_error2.zip (1.8 KB, 164 views)

Reply With Quote
  #8  
Old October 4th, 2003, 06:52 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
if your date field is datetime then you can try this sorry i just skipped through the post but this works

PHP Code:
 date_format(date_field'%W, %M %D, %Y')as date

time_format
(date_field'%r'


the first one gets the date aspect of it formated in date time wed jan etch and the second gets the time as in 12:00:23 am etc.... put the code in your query and the date_field is your field that contains the date =]

Reply With Quote
  #9  
Old October 4th, 2003, 07:57 PM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
It is a timestamp, not a datetime field

Reply With Quote
  #10  
Old October 4th, 2003, 09:54 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
i just read up on it and it seems you can manipulate the timestamp using date_format
check here

Reply With Quote
  #11  
Old October 5th, 2003, 12:11 AM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
I figured out the problem. I had it using the strtotime() function as well. That is what was screwing it up
PHP Code:
//What I had
$posted=date("m/d/Y"strtotime($news['posting_date']));
$edited=date("m/d/Y H:m",strtotime($news['editing_date']));
//What I should have had all along
$posted=date("m/d/Y",$news['posting_date']);
$editing=date("m/d/Y H:m",$news['editing_date']); 

Thank you for all your help guys

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Date() not displaying all information


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |