CodeIgniter Forums
Blog Archives - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Blog Archives (/showthread.php?tid=10186)



Blog Archives - El Forum - 07-22-2008

[eluser]Yash[/eluser]
I've date values in a field ex

2008-06-11 02:07:08

2007-02-23 14:11:11

2007-02-06 14:11:11

Now I need to convert these into text

like

June 2008
Feb 2007 and like so...

Is there any direct function for this.Or I need to write a function.

Thank you


Blog Archives - El Forum - 07-22-2008

[eluser]Pascal Kriete[/eluser]
Where are you getting this string from? I find it easiest to work with unix timestrings.

Php has a function strtotime to get a unix timestamp from a string if you don't have a unix representation. Then you can use the date function to re-format it.


Blog Archives - El Forum - 07-22-2008

[eluser]Yash[/eluser]
Code:
$query = $this->db->query('select DISTINCT PostedDate from posts');
          foreach ($query->result() as $row)
            {    $input[]= date("F Y ",strtotime($row->PostedDate)); }
            
            
          

            $result = array_unique($input);
            var_dump($result);
Output is

array(3) { [0]=> string(11) "April 2003 " [1]=> string(14) "February 2003 " [3]=> string(10) "June 2008 " }

Now I want April 2003 contains a link like www.site.com/blog/2003-04

How to achieve that and Is this a right way to do..


Blog Archives - El Forum - 07-22-2008

[eluser]Yash[/eluser]
Complete working function

Code:
$query = $this->db->query('select DISTINCT PostedDate from posts');
  foreach ($query->result() as $row)
  {

  $input[]= "<a >PostedDate,0,7)."\">".date("F Y ",strtotime($row->PostedDate))."</a>";
            
            
}

$result = array_unique($input);
print_r($result);