PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 12th, 1999, 10:52 PM
Heath
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Struggling a bit with the date command.

I have a MySQL timestamp field called "answers_date" with the value "19990912154608"

So why does this:

echo (date("F j, Y", $myrow["answers_date"]));

yield this:

January 18, 2038?

Thanks in advance...

Reply With Quote
  #2  
Old September 13th, 1999, 01:40 PM
donarb
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
The problem is that your timestamp value is a string, and the date() function expects an integer value. You should use the UNIX_TIMESTAMP() function when returning the answers_date value using an alias, like this:

select UNIX_TIMESTAMP(timestamp_col) as answers_date from my_table;

timestamp_col is the column that contains the timestamp. If the column name is answers_date, then make up a new name to follow 'as' and use that in your php script.

Reply With Quote
  #3  
Old September 13th, 1999, 04:12 PM
Heath
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
This appears to have worked like a
charm, and I appreciate the help.

Trying to find some sort of help with this
from the PHP docs proved impossible, and
the mySQL manual presents all sorts of ways
to turn their goofy timestamp to a normal unix timestamp, but implementing this in PHP turned out to be intellectually challenging.

Thanks again.

Reply With Quote
  #4  
Old September 13th, 1999, 04:46 PM
Heath
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Using a mySQL field as timestamp -- this is my PHP code to query the timestamp using mySQL "UNIX_TIMESTAMP" -- is there a better way than doing two different selects here? This code works fine, but I'd like it to be as effecient as possible:


$result = mysql_query("SELECT * FROM questions where (quest_id=$quest_id)",$db); ## $quest_id is primary key - its the question we're grabbing

$second = mysql_query ("SELECT UNIX_TIMESTAMP(quest_date) as $date from questions where (quest_id=$quest_id)",$db);

## Above, I've already queried this table, and the timestamp value would be in $myrow["quest_date"] per below, but above I query again to get in the UNIX_TIMESTAMP form. This works, but why must I query twice? Is there a way to grab "quest_date" in the first query as UNIX_TIMESTAMP (therefore making second query above no longer needed??)

## the rest of the code goes on to do this:


if ($myrow = mysql_fetch_array($result)) {
## ... blah blah blah, then prints date like this:

echo date ("F j, Y", mktime ($date));

Like I said - this works fine, but seems awfully messy.

Help and comments appreciated.

I am using timestamp because I need the date to be automatically entered when the row is updated.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Date Woes

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap