Is there a way I can change a Text field to a Date field and not toast the data that is already there?
You should not lose any data which already exists in your fields when changing field types - but if you have anything but a UNIX timestamp stored in the existing text field, the Date fieldtype won't know what to do with the data.
UPDATE:
To update your existing fields from your current format (5/14/2013
) to a timestamp for use with the Date fieldtype, put this code in a PHP-enabled template and run it (backup your database first of course):
<?php
$this->EE =& get_instance();
$current = $this->EE->db->query("
SELECT entry_id, field_id_XX FROM exp_channel_data WHERE field_id_XX != ''
");
foreach($current->result_array() as $row)
{
$timestamp = strtotime($row['field_id_XX']);
$this->EE->db->query(
$this->EE->db->update_string('exp_channel_data', array('field_id_XX' => $timestamp), 'entry_id='.$row['entry_id'])
);
}
?>
-
-
-
-
Derek. This is an excellent solution. I really appreciate the assistance on this. – forrest Jun 4 '13 at 17:46