For lists the files exist more than one way, as pointed out in the other answers.
Either way you will have to extract from the name the portion that refers to date, by position or with regular expression.
$arquivo = 'nome_2015-11-13_01.42.22_.csv';
$prefixo = 'nome_';
$dataHora = substr(strlen($prefixo), 19);
To convert to date you have two ways:
1 - with the function DateTime::createFromFormat
(required PHP >= 5.3.0), in which case an object will be returned DateTime
DateTime::createFromFormat('Y-m-d_H.i.s', $dataHora)
2 - with the function strtotime
, will need to make a format conversion, changing the _
for T
, according to the accepted [composite formats], which returns a time stamp:
strtotime($dataHora, str_replace('_', 'T', $dataHora));
It’s a csv a day or power has more?
– rray
If the default format is this for everyone, you can use regex to filter the name date, see: https://ideone.com/rionwn
– user28595