Jump to content


Photo

Wierd date() output


  • Please log in to reply
8 replies to this topic

#1 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 14 July 2006 - 11:43 PM

Ok so Ive have never used the date() function before untill now. I thought I had it all down (simple it seemed) but some how I getting something weird.

$signupdate = date("F d Y" , $row["signupdate"]);
$lastlogin = date("F d Y" , $row["lastlogin"]);

The $row["signupdate"] and $row["lastlogin"] are from a MySQL query and it out put something like this normally: 2006-07-12 23:28:57.

But when I load the page it comes out as: December 31 1969. ???? Why, what, no! Any ideas?

#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 14 July 2006 - 11:46 PM

i think its because the date() functions have diff things like for the dates and stuff i will get u the right form brb

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 14 July 2006 - 11:48 PM

Are you trying to get rid of the time in the $row
if so use str_replace or eregi_repalce or substr
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 14 July 2006 - 11:49 PM

http://us2.php.net/date

thats the page with all the date forms and stuff u have the "F" which displays the word form

#5 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 14 July 2006 - 11:50 PM

did this help u?

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 15 July 2006 - 12:21 AM

The date() function is expecting a UNIX timestamp as the second parameter, not a string. A UNIX timestamp is the number of seconds since 1-1-1970 for the date. To get this number you can use the strtotime() function. So in your case:
<?php
$signupdate = date("F d Y" , strtotime($row["signupdate"]));
$lastlogin = date("F d Y" , strtotime($row["lastlogin"]));
?>

Ken

#7 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 15 July 2006 - 01:05 AM

Cool thx kenrbnsn. That what it was. Thank you alot!

#8 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 15 July 2006 - 01:27 AM

an alternative is to pull the date using MySQL's UNIX_TIMESTAMP() function directly.

#9 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 15 July 2006 - 01:41 AM

Yeah, e.g: "SELECT UNIX_TIMESTAMP(date) as timestamp"
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users