b4dQuetions
b4dQuetions

Reputation: 1619

how can select timestamp column

hy I have uisng laravel 4
I have data like this: 2016-02-12 18:32:19
I have query like this

 echo $result = SourceManagement::get(array('id', 'created_at', DB::raw("date_format(from_unixtime(created_at), '%Y') as created_at")));  

 // print_r($result);

why Output to be like this :

[  
   {  
      "id":1,
      "created_at":null
   },
   {  
      "id":3,
      "created_at":null
   },
   {  
      "id":4,
      "created_at":null
   },
   {  
      "id":7,
      "created_at":null
   },
   {  
      "id":8,
      "created_at":null
   },
   {  
      "id":9,
      "created_at":null
   },
   {  
      "id":10,
      "created_at":null
   },
   {  
      "id":11,
      "created_at":null
   },
   {  
      "id":12,
      "created_at":null
   },
   {  
      "id":13,
      "created_at":null
   },
   {  
      "id":14,
      "created_at":null
   }
]

Upvotes: 0

Views: 39

Answers (1)

Qazi
Qazi

Reputation: 5135

Update your query like this, that might solve your problem, as per my understanding you are overwriting the default column name, thats why you getting null, I tested below query, its working fine.

$result = SourceManagement::get(array('id', 'created_at', DB::raw("date_format(created_at, '%Y') as created_at_custom"))); 

Upvotes: 1

Related Questions