Welcome Guest, Not a member yet? Register   Sign In
date format in query
#1

[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
#2

[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');
#3

[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');
#4

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

[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
#6

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

[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
#8

[eluser]Sagar Ratnaparkhi[/eluser]
Try this

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





Theme © iAndrew 2016 - Forum software by © MyBB