Travis Michael Heller
Travis Michael Heller

Reputation: 1248

Working with timestamps

Not sure on how to format the timestamp value so it reads "February 15, 2013 12:34pm" right now it just reads "2013-03-15 12:04:11".

I have read a ton of post and none of them seem to help with my situation or show me a correct answer and how to implement it. Any help would be much appreciated.

Here is my view

<section class="noteinfo">
      <p><span>Note:</span>&nbsp; <?php echo $row->folderName; ?></p> 
      <p><span>Created:</span> &nbsp;<?php echo $row->time; ?></p>
</section>

Here is my controller code

function create() {
    if(array_key_exists('createFolder',$_POST)) {
        $data = array(
          'folderName' => $this->input->post('folderName')
          // 'time' => date('Y-m-d H:i:s',now())
        );
        $data = str_replace(array(' ', '.', '?', '*', '%', '/'), '_', $data);
        $datestring = "Year: %Y Month: %m Day: %d - %h:%i %a";
        $time = time();
        // $data = str_replace(' ', '_', $data);
        $this->index_model->createFolder($data, $datestring, $time);
     }
     $this->foldercreated();
}

Here is my Model code

function createFolder($data) {
    $this->db->where('time', 'time');
    $this->db->where('folderName', 'folderName');
    $this->db->insert('senior', $data);
    return;
}

Upvotes: 0

Views: 46

Answers (1)

Yada
Yada

Reputation: 31225

Use date() and strtotime()

For February 15, 2013 12:34pm to format is 'F j, Y g:ia'

<p><span>Created:</span> &nbsp;<?php echo date('F j, Y g:ia', strtotime($row->time)); ?></p>

Upvotes: 1

Related Questions