PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello... I'm wondering how to get the date text out of a file name that is being upload on a server, and adding this value to the database itself...
I mean :
A file called XX_XXXXX_XXXXX_XXX_03042005.csv is generated every day. And the date is the last digits. When inserting the values stored in in a database, can i add in an extra field where i can store the date value?
I think i can use the explode funtion to breack the name apart, but then?? How to store the last digit? Maybe assigning each value to an array?
$filename = "XX_XXXXX_XXXXX_XXX_03042005.csv";
preg_match('/_(\d{8})\.csv$/', $filename, $matches); //Extract the date
$date = $matches[1]; //This is your date
echo $date;
$filename = "Transaction_Response_Time_Monitoring_07032005.csv";
//separate and collect to an array each element separated by _
$namepart = explode("_", $filename);
//get last one containing the date plus the extensiona and again explode it
$date_container = explode(".", $namepart[4]);
//assign the value (text only) to the variable
$date = $date_container[0];
echo "<pre>";
echo "namepart[0] =".$namepart[0]."<br>";
echo "namepart[1] =".$namepart[1]."<br>";
echo "namepart[2] =".$namepart[2]."<br>";
echo "namepart[3] =".$namepart[3]."<br>";
echo "namepart[4] =".$namepart[4]."<br>";
echo "The resulting date is <b>".$date."</b><br>";
But then once i got this, how can i insert this in the database while uploading? Malcolmboston, i get your advice, but can i do it at the same time of the upload or do i have to set up another step?
function GetDate ($string)
{
// function to get date from string here
return $string;
}
function InsertDateMySQL ($string)
{
// function to insert into MySQL
}
guys, first of all let me tell you that this forum rules...
thanks to your help i'm getting to the result expected !
Now i'm checking how to work on the dateformat, as it is returned as 02032005 (ddmmyyyy) and i want to insert it in a MySQL database in a different format... like yyyy-mm-dd
Unfortunatelly i've not yet installed PHP5 on the server...