Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with dates

Status
Not open for further replies.

RZillmer

Programmer
Nov 20, 2001
42
US
I'm shy and girls don't seem to like me.

Now that the lame attempt at humor is out of the way, my problem....

I insert the current date into my mysql database with this statement (edited out unneccessary fields):

$sql = sprintf ("INSERT INTO articles (datePublished) VALUES (now())");

datePublished is a datetime field. I know the info is getting there correctly because I can view it when I display the field with something like $articleInfo["datePublished"] after a SELECT query. It is there and correct. The problem comes when I try to format it into [mm.dd.yy] format. Using date("[m.d.y]", $articleInfo["datePublished"]) gives me [12.31.69] for some reason. I also tried formatting it in my SELECT statement with the following query:

mysql_query("SELECT *, date_format(\"[%m.%d.%y]\", datePublished) as formatDate FROM articles", $db);

If I use that $articleInfo["formatDate"] just ends up being blank.

Any help would be appreciated. Thanks.

 
date() requires that your input be an integer of the Unix Epoch timestamp.

Try

date ("[m d y]", strtotime($articleInfo["datePublished"])) ______________________________________________________________________
TANSTAAFL!
 
yup....the strtotime is what I needed. Found the answer and your reply within two minutes of each other. Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top