0

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. do you have any idea of this ? change from 33250400 to 01-47 PM. It would be great if anybody could figure out, thank you so much in advance!.

Expected 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')

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response, I've been mistaken from my question. I just want to get the value to those I've been marked red in the image into hour and minutes and then the format of the file like .csv
The output should look like this 2021-03-30-01-47 PM.csv do you have idea of this ? from 33250400 to 01-47 PM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.