Jump to content

[SOLVED] Basic substr problem


robindean

Recommended Posts

I'm still getting to know php (newbie). I need to remove zeros from a blogger generated archive script.

 

The script receives a yyyymmdd date string, let's say it's 20070401 (next month). I'm trying to return it as 4.1.2007 but must remove the zeros first, as it currently returns 04.01.2007 ... what's the math here? - or - Do you have a better method for all of this?

 

<bloggerarchives>

$y20070401 = substr('20070401', 0, 4);

$m20070401 = substr('20070401', -4, 2);

$d20070401 = substr('20070401', 6);

$p20070401 = $m20070401.'.'.$d20070401.'.'.$y20070401;

</bloggerarchives>

Link to comment
https://forums.phpfreaks.com/topic/42739-solved-basic-substr-problem/
Share on other sites

The mktime() function might be of use:

 

// get the unix time stamp
$time = mktime(0,0,0,$month, $day, $year);

$dateDisplay = date('m.n.Y', $time);

 

References:

http://us2.php.net/manual/en/function.mktime.php

 

http://us2.php.net/manual/en/function.date.php

 

 

--FrosT

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.