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.


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):

    $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->update_string('exp_channel_data', array('field_id_XX' => $timestamp), 'entry_id='.$row['entry_id'])
  • Hi Derek, the current values are in the format: 5/14/2013.
    – forrest
    Jun 3 '13 at 20:42
  • Just added some code to do the conversion for you. Jun 3 '13 at 20:53
  • Hi Derek, thank you very much. I'll give it a try and get back to you.
    – forrest
    Jun 3 '13 at 20:57
  • Derek. This is an excellent solution. I really appreciate the assistance on this.
    – forrest
    Jun 4 '13 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.