Jump to content

Explode of date into a certain format


jschofield

Recommended Posts

Hello all. My script is below. Ok here is what I am having trouble with. What I am trying to do is take a date that is in one column of an excel file and change the format of that date. Right now the date is 2/22/2007. I want the date to be 02/22/2007. I was thinking I could explode the date by the "/" and then do the mktime to get it the way I want. I dont know the mktime well so not sure if it will work. Any help would be huge and help me a lot. I have spent the last 4 hours trying different thing with no luck....PLEASE HELP. Thanks Johnnie

 

<?php

 

$inputfile = "C:/SMDIM/Data/RMS_Attendance";

$outputfile = "C:/SMDIM/Data/RMS_Attendance_Data.csv";

$logfilename = "C:/SMDIM/Logs/GRMS_Attendnace_Log.txt";

include'C:/SMDIM/Translators/importlibrary.inc.php';

$count = 0;

//open the file

if(!$out = fopen($outputfile, "w")) {

wlogdie("Unable to open $outfile to write");

}else{

wlog("Opened $outputfile for writing");

}

 

if(!$in = fopen($inputfile, "r")) {

wlogdie("Failed to open $inputfile for reading");

}else{

wlog("Opened $inputfile for reading");

}

while($line = fgetcsv($in, 1000, "\t")) {

$row = str_replace("\t", ",", $line);

$row = str_replace(" ", "English", $line);

$date = explode("/", $row[6]);

$temp  = array($row[1],$row[5], $row[6], $row[7]);

 

 

$count++;

writeLine($out, $temp, $date);

}

if($count !== '0') {

wlog("finished the import with a total of $count records");

}else{

wlog("Failed to import data");

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/39667-explode-of-date-into-a-certain-format/
Share on other sites

first of all before I have a look deeper have a look at this

<?php
while($line = fgetcsv($in, 1000, "\t")) {
   $row = str_replace("\t", ",", $line);
   $row = str_replace(" ", "English", $line);
?>

line 1 While - understand that perfectly

line 2 change something to $row by removing the tabs from $line and changing them to commas - understand that perfectly

line 3 change something else to $row by working on $line again -  negating the line above it - lost me here

 

hopefuly that makes sense

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.