Forum Moderators: coopster

Message Too Old, No Replies

break down date variable

         

CodilX

3:44 pm on Apr 7, 2008 (gmt 0)

10+ Year Member



Hi,

can someone tell me how to break down a date variable?

input:
$date="2008-04-07";

output:
$year="2008";
$month="04";
$day="07";

coopster

4:14 pm on Apr 7, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



list and explode work great for something like this
list [php.net]($yyyy, $mm, $dd) = explode [php.net]('-', '2008-04-07');

CodilX

4:53 pm on Apr 7, 2008 (gmt 0)

10+ Year Member



thanks so much, sounds simple but I just couldn't figure it out :)

dreamcatcher

6:29 am on Apr 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As a learning curve, you can also use substr [uk.php.net]:

$date = '2008-04-08';
$year = substr($date,0,4);
$month = substr($date,5,2);
$day = substr($date,8,2);

Personally, I would use Coop`s method, but just thought I would offer an alternative.

dc