1,105,395 Community Members

Date Format

Member Avatar
mtho
Newbie Poster
16 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi Guys Im a newbie and a somewhat beginner in PHP
Here is my problem

I want to insert this date format - DATE_FORMAT(news.updated, '%%M %%e, %%Y') AS formatted FROM news


into this already existing sql statement - $sql = "SELECT * FROM authors aut, news new WHERE aut.aurthor_id=new.arthor_id AND article_id=1 ORDER BY updated DESC LIMIT 15";


I have tried all sorts of way but keep getting this (or similar) error message - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(news.updated, '%%M %%e, %%Y') AS formatted from news WHERE aut.aurthor_id=new.a' at line 1

Member Avatar
StephNicolaou
Posting Whiz in Training
204 posts since Nov 2007
Reputation Points: 32 [?]
Q&As Helped to Solve: 18 [?]
Skill Endorsements: 0 [?]
 
0
 

Modify the double percentage symbols to a single percentage symbol, e.g. '%M %e, %Y'

Double percentages are a literal % symbol.

Here is a MySQL guide to every format available:

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format

Hope that helps :)

Member Avatar
diafol
Where are my eyes?
12,949 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,846 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

Perhpas you want to check your spelling too:

authors aut, news new WHERE aut.aurthor_id=new.arthor_id

They may be right in your case, but 3 different ways of spelling author?

Member Avatar
Que336
Light Poster
26 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Your question doesn't make sense...I think you have a field with a timestamp and you want it to be displayed as a normal date in PHP. Is that what you mean. I don't know how to do it but I'm sure ARDAV can help you.

Member Avatar
weekendrockstar
Junior Poster in Training
71 posts since Dec 2010
Reputation Points: 12 [?]
Q&As Helped to Solve: 16 [?]
Skill Endorsements: 0 [?]
 
0
 

The link that StephNicolaou provided should help you out. You can also look at http://www.tizag.com/phpT/phpdate.php which gives much of the same information but Tizag is a good beginners site and they tend to explain things in as simplified way as they can.

PHP has the built-in function 'date' which gets the timestamp from the server and within the parenthesis of the date function you can specify how you want the date to be displayed.

SO you could do something like:

<?php
$date_time = date("m/d/y");
?>

Then you have the date and time in the format that you want it displayed and can send the variable with your query to have it saved in the database.

Now at the time of this posting the value of $date_time would be "03/13/12" which doesn't show the name of the day of the week or the time but you can use either of the function links we've given you to format it how you want.

To test the format you can make your script print out the value of $date_time without saving it to the database so you can see how the format would actually look. And then you can change the parameters of 'date' to get it to look how you want.

Member Avatar
rajeevphp2011
Light Poster
26 posts since Nov 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 1 [?]
 
0
 

echo date('d-m-Y', strtotime($date));

for change date format in php

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: