CodeIgniter Forums
Date in text field - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Date in text field (/showthread.php?tid=3197)



Date in text field - El Forum - 09-15-2007

[eluser]Kemik[/eluser]
Hello,

I know this is a weird question but how do you guys/girls get dates from the user? I'm trying a text field and then storing it in the database (DATE format) however the date isn't saved, just the rest of the query. I've checked all the names to make sure its not a silly mistake but they're all correct.

Fancy taking a look please?

Code:
<?php

$this->validation->set_error_delimiters('<p class="important" style="width: 300px;">', '</p>');
        
$rules['datetime']        = "trim|required|callback_datetime|xss_clean";
$rules['occurs']        = "trim|required|callback_occurs|xss_clean";
$rules['event']         = "trim|required|xss_clean|strip_tags";
        
$this->validation->set_rules($rules);
        
$fields['datetime']        = 'Date';
$fields['occurs']        = 'Occurs';
$fields['event']        = 'Event';
    
$this->validation->set_fields($fields);
        
if ($this->validation->run() == TRUE) {        
            
if ($this->input->post('occurs') == 'one-time') {
            
  $insert = array(
    'date' => $this->input->post('datetime') ,
    'details' => $this->input->post('event')
  );
    
  $this->db->insert('one_events', $insert);
                
  $data['message'] = TRUE;
}
}
?&gt;

The date is validated for dd-mm-yyyy


Date in text field - El Forum - 09-15-2007

[eluser]座頭市[/eluser]
Two possibilities come to mind:

1) There's problem with your callback - it might be useful to post the code.

2) If you're using MySQL, the date format should be YYYY-MM-DD, not DD-MM-YYYY


Date in text field - El Forum - 09-15-2007

[eluser]Kemik[/eluser]
The callback is good. It doesn't show an error when validating.

The second part might the problem, but even if I ask the user to put it in YYYY-mm-dd format it still doesn't insert Sad


Date in text field - El Forum - 09-16-2007

[eluser]Michael Wales[/eluser]
Try inserting it as:
Code:
date('Y-m-d', strtotime($this->input->post('datetime')));