CodeIgniter Forums
date format in query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: date format in query (/showthread.php?tid=43562)



date format in query - El Forum - 07-15-2011

[eluser]Rodrigo Berlinck[/eluser]
hello guys,
i always use date_format from SQL for convert date but how make this from querys of ci?
exemple:

Code:
$this->db->where("id",$id");
$this->db->date("yy/mm/dd",$row->date);
$this->db->get("news");

thanks


date format in query - El Forum - 07-16-2011

[eluser]steelaz[/eluser]
Wrong forum, next time please use this one if you want to ask questions - http://ellislab.com/forums/viewforum/127/

To solve your problem, try:

Code:
$this->db->select('DATE_FORMAT(date, "%y/%m/%d") AS date');



date format in query - El Forum - 07-16-2011

[eluser]Bart v B[/eluser]
Almost right..
The alias needs to be other then de column name.
Otherwise you can get in trouble with things if you want to do more. Smile
Code:
$this->db->select('DATE_FORMAT(date, "%y/%m/%d") AS date_NL');



date format in query - El Forum - 07-16-2011

[eluser]Rodrigo Berlinck[/eluser]
sorry for posting in the wrong forum.
I understood perfectly, thanks for the help


date format in query - El Forum - 08-19-2012

[eluser]Hammoc Matthew[/eluser]
I write code the same above but it error. help me!

Error Number: 1064

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 'FROM (`tb_news`) ORDER BY `new_created` DESC LIMIT 8' at line 2

SELECT DATE_FORMAT(new_created, `"%y/%m/%d")` AS new_day FROM (`tb_news`) ORDER BY `new_created` DESC LIMIT 8

Filename: E:\WWW\gamemobile24h\system\database\DB_driver.php

Line Number: 330


date format in query - El Forum - 08-19-2012

[eluser]Sagar Ratnaparkhi[/eluser]
As per query you posted, it looks like you added extra quote after date_format syntax.


date format in query - El Forum - 08-20-2012

[eluser]Hammoc Matthew[/eluser]
This is my query. Can you help me?

$this->db->select('*');
$this->db->select('DATE_FORMAT(new_created,"%d/%m") as "day"')

but an error happened as the code above


date format in query - El Forum - 08-20-2012

[eluser]Sagar Ratnaparkhi[/eluser]
Try this

$this->db->select("DATE_FORMAT(new_created,'%d/%m') as day");