I have a file that lists datetime such as:
060000
941070000
How would I convert a variable $datetime from 060000 to 6:00:00 and convert the second date to 07:00:00 ignoring the 941 that precedes it ?
datetime formatting
Moderator: General Moderators
Re: datetime formatting
Okay,
I figured out how to convert the times into proper format 00:00:00.
How do I use regular expressions so if it starts with 941 to replace the 941 with nothing. For some reason some of the times are like 941060000 which should translate to 06:00:00.
I tried this but it doesnt work:
$time = $fields[1];
$find = "^941";
$replace = "";
$newtime = preg_replace($find,$replace,$time);
This doesnt work ... what could I be doing wrong ?
I figured out how to convert the times into proper format 00:00:00.
How do I use regular expressions so if it starts with 941 to replace the 941 with nothing. For some reason some of the times are like 941060000 which should translate to 06:00:00.
I tried this but it doesnt work:
$time = $fields[1];
$find = "^941";
$replace = "";
$newtime = preg_replace($find,$replace,$time);
This doesnt work ... what could I be doing wrong ?
Re: datetime formatting
Where is this data coming from?
Re: datetime formatting
if the first 3 charactars are ALWAYS ignored, then just substr() the last part out.
Code: Select all
$time = substr($time, 3, 6);Re: datetime formatting
Its coming from a file heres 3 lines:califdon wrote:Where is this data coming from?
300 941223109 000020 DDD-0130
302 223130 002830 FFF-2783
307 230000 000230 EEE-3211
as you can see the second column has the time. Sometimes it has 941 which has to be ignored so the substr cant work.
Re: datetime formatting
How would I use preg_replace if I wanted ?
I tried this but didnt work:
I tried this but didnt work:
Code: Select all
$fields[1] = "941060030";
$time = $fields[1];
$newtime = preg_replace('(PR1)','',$time);
echo $newtime;