jschofield Posted February 22, 2007 Share Posted February 22, 2007 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 More sharing options...
craygo Posted February 22, 2007 Share Posted February 22, 2007 use php strtotime function. $date = date("m/d/Y", strtotime($row[6])); echo $date; Ray Link to comment https://forums.phpfreaks.com/topic/39667-explode-of-date-into-a-certain-format/#findComment-191498 Share on other sites More sharing options...
paul2463 Posted February 22, 2007 Share Posted February 22, 2007 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 Link to comment https://forums.phpfreaks.com/topic/39667-explode-of-date-into-a-certain-format/#findComment-191505 Share on other sites More sharing options...
jschofield Posted February 22, 2007 Author Share Posted February 22, 2007 Ray, It worked!!! You are the MAN. You just made my day!!! Thank you and thanks to all that replied. WoooooHooooo. Link to comment https://forums.phpfreaks.com/topic/39667-explode-of-date-into-a-certain-format/#findComment-191508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.