Welcome Guest, Not a member yet? Register   Sign In
Mysql Date Format
#1

[eluser]tj[/eluser]
I need to fetch date in this format from data base can any one tell how to rewrite this pice in codeigniter format

DATE_FORMAT(tasks.start_date,'%b %D %y' ) as task_stdate,

thanks in advance;
#2

[eluser]umefarooq[/eluser]
if you are not using active record just simple query then your query will be lik

Code:
$query = "select DATE_FORMAT(tasks.start_date,’%b %D %y’ ) form table";

if you are using active

Code:
$this->db->select("DATE_FORMAT(tasks.start_date,’%b %D %y’ )",FALSE)
#3

[eluser]tj[/eluser]
tnx 4 ur reply my need is to change the field name in normal query we can write it as
DATE_FORMAT(tasks.start_date,’%b %D %y’ ) as task_stdate, and change the field name
how is it done in active records i have 2 field with same name from different tables

my query is

$this->db->select(' tasks.id,
tasks.project_id,
tasks.business_id,
tasks.title,
tasks.description,
tasks.task_priority,
tasks.start_date,
tasks.end_business_user_id,
business_client.name,
satff.staff_name,
mytasks.start_date,
mytasks.task_status,
mytasks.end_date');
$this->db->from('tasks');
$this->db->join('business_client', 'business_client.id = tasks.started_business_client_id');
$this->db->join('mytasks', 'mytasks.task_id = tasks.id', 'left');
$this->db->join('satff', 'satff.id = mytasks.staff_id', 'left');
$this->db->limit($num, $offset);
$q = $this->db->get();
return $q->result_array();
#4

[eluser]tj[/eluser]
[
#5

[eluser]umefarooq[/eluser]
its is also easy same as writing normal query you can use as in you active record select

Code:
$this->db->select("DATE_FORMAT(tasks.start_date,’%b %D %y’ ) as task_stdate, DATE_FORMAT(mytasks.start_date,’%b %D %y’ ) as mytask_stdate ",FALSE)

try it and update your result here.
#6

[eluser]tj[/eluser]
its not working

Unknown column '’%b' in 'field list'

this error is showing.is it not possible in codeigniter.
#7

[eluser]umefarooq[/eluser]
hi if you copy from here and paste in you code then it is a special char is there remove char ’ and replace with ' it will work fine.and it is possible in CI to use mysql date_format im using it for my project build on CI.
#8

[eluser]tj[/eluser]
thank u very much .it works fine.
#9

[eluser]saidai jagan[/eluser]
[quote author="umefarooq" date="1261578039"]hi if you copy from here and paste in you code then it is a special char is there remove char ’ and replace with ' it will work fine.[/quote] Wink




Theme © iAndrew 2016 - Forum software by © MyBB