简体   繁体   English

将varchar字符串转换为日期格式查询Laravel

[英]Convert varchar string into Date format Query Laravel

I'm having a trouble on how can I convert my filename into date time format.我在如何将文件名转换为日期时间格式时遇到问题。 The format of my filename is varchar and The problem is the last part of the name file is not formatted as a date it should be formatted in hour , minutes and AM/PM see my sample image below.我的文件名的格式是 varchar,问题是名称文件的最后一部分没有格式化为日期,它应该格式化为hourminutesAM/PM ,请参见下面的示例图像。 do you have any idea of this?你知道吗? change from 33250400 to 01-47 PM.从 33250400 更改为 01-47 PM。 It would be great if anybody could figure out, thank you so much in advance..如果有人能弄清楚,那就太好了,在此先感谢您..

Expected output预期 output

2021-03-30-01-47 PM.csv

sample-Image样本图像

What I've tried我试过的

 ->select(['table.*',DB::raw(' DATE_FORMAT(table.file_name, "%Y-%m-%d-%h:%i %p") AS final_date')

You are passing filename to DATE_FORMAT function which contains.csv extension that is why you are not getting your expected output but if you still want date time format of filename then you can select records from database and you can remove.csv extension from each filename record string and then use date function to get your desired output You are passing filename to DATE_FORMAT function which contains.csv extension that is why you are not getting your expected output but if you still want date time format of filename then you can select records from database and you can remove.csv extension from each filename record字符串,然后使用日期 function 得到您想要的 output

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM