s_ainley87 Posted July 15, 2008 Share Posted July 15, 2008 <?php class CreateCSV{ function create($sql, $isPrintFieldName = true, $isQuoted = true){ $q = mysql_query($sql) or die("Error: ".mysql_error()); $csv = $head = $ctn = ''; $hasPrintHead = false; while($r = mysql_fetch_assoc($q)){ if(!$hasPrintHead && $isPrintFieldName == true){ $csv_value = array(); foreach($r as $field => $value){ $csv_value[] = $field; } $hasPrintHead = true; $csv .= implode(',', $csv_value)."<br/><br/>"; } //Print the content... $csv_value = array(); foreach($r as $field => $value){ $cvs_value = date("d.m.o", $cvs_value[1]); $csv_value[] = $isQuoted == true ? '"'.$value.'"' : $value; } $csv .= implode(',', $csv_value)."<br/><br/>"; } return $csv; } } ?> The above code create a layout that can be copied across to excell and saved as csv. My problem is that I cannot for the life of me work out how to change the timestamp data I have within the array to m.d.y format. The array is called $csv_value and I know the timestamp is held in [2]. Does any one have any ideas? Link to comment https://forums.phpfreaks.com/topic/114848-php-changing-a-format-inside-an-array/ Share on other sites More sharing options...
discomatt Posted July 15, 2008 Share Posted July 15, 2008 What kind of timestamp are we dealing with, Unix or MySQL? Link to comment https://forums.phpfreaks.com/topic/114848-php-changing-a-format-inside-an-array/#findComment-590568 Share on other sites More sharing options...
kenrbnsn Posted July 15, 2008 Share Posted July 15, 2008 Try: <?php $csv_value[2] = date('m.d.y',strtotime($csv_value[2])); ?> Ken Link to comment https://forums.phpfreaks.com/topic/114848-php-changing-a-format-inside-an-array/#findComment-590569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.