Forum Moderators: coopster

Message Too Old, No Replies

Explode Function on Date

         

gbrown442

7:47 am on Jul 28, 2011 (gmt 0)

10+ Year Member



Hi,

I'm currently using the follow code to explode a date:

PHP Code:

list($y, $m, $d) = explode('-', substr($postted_date, 0, 9));


The postted_date looks like this:

2011-07-26 17:18:20

Its definitely breaking up the date to list the year, month and day, but for example with the above date for month its only displaying the '7' and I need it to display the month as '07'. Same case with the day.

Suggestions?

Thanks

penders

9:34 am on Jul 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



substr($postted_date, 0, 9)


It should be 10, not 9 for the length parameter.

But if it's returning '7' and not '07' then this is probably how you are displaying it, assuming your $postted_date really is a string?

$postted_date = '2011-07-26 17:18:20'; 
list($y, $m, $d) = explode('-', substr($postted_date, 0, 10));
echo "$y / $m / $d"; // Outputs: 2011 / 07 / 26

gbrown442

9:47 am on Jul 28, 2011 (gmt 0)

10+ Year Member



I think I've been looking at code for to long.. thanks for the help!

proexe

12:16 pm on Jul 28, 2011 (gmt 0)

10+ Year Member



It should be 10, not 9 for the length parameter.

yep my mistake, when I posted that example, in another post