View Full Version : Date: dd.mm.yyyy
Yaggles
08-22-2005, 03:21 AM
I have a news system that sends the date as NOW() (mysql function) into a DATE field. I was wondering how I would be able to send the current date into the DATE field as something like this:
dd.mm.yyyy (e.g. 02.06.1948 would be June 2, 1948).
I checked the DATE_FORMAT function, but I don't entirely get it. COuld someone help me out here?
Also, I know PHP in case I need to add some PHP in there to make it work.
Brandoe85
08-22-2005, 03:51 AM
You should still be able to send the date in as Now(), but just use date_format() when you're reading out the dates, and format it however you'd like. What are you having problems with specifically? I would assume something like this should work:
SELECT DATE_FORMAT(dateField, '%d.%m.%Y') FROM table
Good luck
Yaggles
08-22-2005, 12:19 PM
Thanks! I'll try out that bit of code and see if it works and post back if it does.
I'm not having problems, really, but I just wanted to know how to do it! Thanks!
-Yaggles
Brandoe85
08-22-2005, 09:32 PM
You're welcome :)
Don't forget to look at the Date and Time functions (http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html) in the manual, which has an example of using date_format().
Good luck
Yaggles
08-23-2005, 12:35 AM
Ok... here's my query:
SELECT title, content, id, DATE_FORMAT(date, \'%d.%m.%Y\') FROM news ORDER BY `date` DESC LIMIT 5
I can't get it to let me define the date. I do the $result = mysql_query('...'); and then I go
while($row = mysql_fetch_object($result))
{
$date = $row->date;
$title = $row->title;
$content = $row->content;
$id = $row->id;
}
It will let me use every other variable BUT date (it comes out blank).
What did I do wrong?
EDIT: I searched around a little on the net and found that I just needed to add "AS date" after the date_format thing!
Thanks for all your help! I'll be sure to post a new thread if I need anything else!
-Yaggles
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.