Jump to content


Photo

date string problem


  • Please log in to reply
2 replies to this topic

#1 Trevors

Trevors
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 18 April 2006 - 06:13 PM

Heya all

Im pretty new to php and im trying to code my own blog and im having problem printing date but a bit differently.
Like this

(0) April 2006
(5) March 2006
(3) February 2006
(6) January 2006
(2) December 2005
(1) November 2005
(0) October 2005
(5) September 2005
(2) August 2005
(1) July 2005

(4) thats how many blog entries there is that month.

My date string looks like this "2006-01-01 01:11:11"
I had a look at preg_split and integer but didnt understand much i would appreciate it very much if someone could help me out im kinda stuck big time hehe.

Best Regards
Trevors

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 18 April 2006 - 07:14 PM

Take a look at the [a href=\"http://www.php.net/strtotime\" target=\"_blank\"]strtotime()[/a] and [a href=\"http://www.php.net/date\" target=\"_blank\"]date()[/a] functions.
<?php
$blog_date = '2006-01-01 01:11:11';
$cnt = 6;
echo '(' . $cnt . ') ' . date('F Y',strtotime($blog_date)) . '<br>';
?>

Ken

#3 ypirc

ypirc
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 18 April 2006 - 08:09 PM

That looks like a MySQL timestamp, so if it is, you should format it within MySQL. You can do this with the following: [a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html[/a]

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]mysql> [span style=\'color:blue;font-weight:bold\']SELECT[/span] DATE_FORMAT(NOW(), '%M %Y');
+-----------------------------+
| DATE_FORMAT(NOW(), '%M %Y') |
+-----------------------------+
| April 2006 |
+-----------------------------+
1 row in set (0.00 sec) [!--sql2--][/div][!--sql3--]

Replace NOW() with the name of your date column.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users