change default date format laravel sql query

帅比萌擦擦* 提交于 2019-12-30 17:11:35

问题


I want to change date out put from following SELECT query to DD/MM/YYY format . pls advice.

this is what I tried so far

  ->select('time_sheets.progress',DATE_FORMAT('time_sheets.date', "%d/%l/%Y") ,'role_users.role_id','roles.role_name')

回答1:


Instead of using ->select you can use selectRaw to allow raw SQL query so you can use:

->selectRaw('time_sheets.progress, DATE_FORMAT(time_sheets.date, "%d/%l/%Y"), role_users.role_id, roles.role_name');



回答2:


->select('time_sheets.progress',\DB::raw('DATE_FORMAT(p.created_at,\'%d-%m-%Y\') as data')), role_users.role_id, roles.role_name');

Hope to help someone else !




回答3:


->select(DB::raw('DATE_FORMAT(FROM_UNIXTIME(column_name), "%Y-%m-%d %h:%i:%s") as cstime_value'))


来源:https://stackoverflow.com/questions/33740827/change-default-date-format-laravel-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!