MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 3rd, 2004, 08:26 PM
mph mph is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 12 mph User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 0
Exclamation MySQL datetime w/php

I am trying to convert a mySQL datetime to a readable format. The default for datetime is 0000-00-00 00:00:00. When I use the code below, I get the correct date and day, just not the correct time.

Saturday, 04.03.04 @ 00:00am.



PHP Code:
function formatDate($val)
{
    
$arr explode("-"$val);
    return 
date("l, m.j.y @ H:ia"mktime(0,0,0$arr[1], $arr[2], $arr[0]));





any help appreciated

Reply With Quote
  #2  
Old April 5th, 2004, 07:51 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
There's a few different solutions... first of all, you could format the actual return result using the SQL statement...

SELECT DATE_FORMAT(date_field, '%W, %y.%m.%e @ %h:%i %p') FROM table

Refer to this: http://www.mysql.com/doc/en/Date_an..._functions.html


Or you could try the PHP date functions:
http://ca3.php.net/manual/en/function.date.php

Reply With Quote
  #3  
Old April 6th, 2004, 02:10 AM
osxboy osxboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 2 osxboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
From the php manual:

[PHP]***
mktime ( [int hour, int minute , int second , int month , int day , int year )
[PHP]

So you're passing 0 for the hour, minute and seconds in your code so the time you're displaying is correct.

HTH

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > MySQL datetime w/php


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway