Jump to content

date string problem


Trevors

Recommended Posts

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
Link to comment
Share on other sites

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.
[code]<?php
$blog_date = '2006-01-01 01:11:11';
$cnt = 6;
echo '(' . $cnt . ') ' . date('F Y',strtotime($blog_date)) . '<br>';
?>[/code]

Ken
Link to comment
Share on other sites

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[color=orange]>[/color] [span style=\'color:blue;font-weight:bold\']SELECT[/span] DATE_FORMAT(NOW(), [color=red]'%M %Y'[/color]);
[color=orange]+[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]+[/color]
| DATE_FORMAT(NOW(), [color=red]'%M %Y'[/color]) |
[color=orange]+[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]+[/color]
| April 2006 |
[color=orange]+[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]-[/color][color=orange]+[/color]
1 row [color=green]in[/color] set (0.00 sec) [!--sql2--][/div][!--sql3--]

Replace NOW() with the name of your date column.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.