I am working on some data migration process, with consists of loads of CSV's
The problem I'm facing now is that the data file I am working with has 2 columns, namely "date" and "time". Now, date itself doesn't have a problem. My "time" column can come in any format, i.e. H:i
, or H:i:s
. Regardless of the format, I want my output to be d/m/Y H:i:s
, and to just append 00 if seconds is not given.
Carbon's createFromFormat requires me to specify what my input format is, which I can't. Currently what I am doing is using Excel to split my CSV files into different files according to the time format, then import them separately, but it's taking too much time.
I can't seem to find a function that allows me to do this either:
if(getSecondsFromTime){
Carbon::createFromFormat($string, 'd/m/Y H:i:s');
}else{
Carbon::createFromFormat($string, 'd/m/Y H:i');
}
Does Carbon/PHP Datetime has a function that I am unaware of that can do this? Or do I have to resolve to regex to do what I need?