Timedate Help
Timedate Help
hmmy Sunday 24th January 2016, 23:45:06Hi,
Can you help me getting the following code to work?
Can you help me getting the following code to work?
public static function toDate($id, $pattern = 'j M \'y')
{
global $lang;
$timestamp = strtotime(substr($id, 0, 16));
$diff = time() - $timestamp;
if($pattern === 'j M \'y' && $diff < 2628000) //1 week
{
$periods = array(604800 => 'w', 86400 => 'd', 3600 => 'h', 60 => 'm', 1 => 's');
foreach($periods as $key => $value)
{
if($diff >= $key)
{
$num = (int) ($diff / $key);
return $num. '' .$value. '';
}
}
}
if (date('Y') == date('Y', $timestamp)) {
return date('j M', $timestamp);
}
else
return date($pattern, $timestamp);
}
Replies 7
Try this:
public static function toDate($id, $pattern = 'j M Y')
{
global $lang;
$timestamp = strtotime(substr($id, 0, 16));
$diff = time() - $timestamp;
if($pattern === 'j M Y' && $diff < 2628000) //1 week
{
$periods = array(604800 => 'w', 86400 => 'd', 3600 => 'h', 60 => 'm', 1 => 's');
foreach($periods as $key => $value)
{
if($diff >= $key)
{
$num = (int) ($diff / $key);
return $num.$value;
}
}
}
if (date('Y') == date('Y', $timestamp))
return date('j M', $timestamp);
else
return date($pattern, $timestamp);
}
- Before ask a question, read the documentation.
- 🎉 Featured as #1 product of the day on Product Hunt
- Please like in alternativeto.net 👍🏻
- ╰☆╮Flatboard╰☆╮ is a open source and community contributions are essential to project success!
- <TextField>, my new CMS project designed by a passionate developer, for developers!
- My last project Fast⚡︎CMS, a Flat-File cms.
- I am currently busy 😫.
- Before ask a question, read the documentation.
- 🎉 Featured as #1 product of the day on Product Hunt
- Please like in alternativeto.net 👍🏻
- ╰☆╮Flatboard╰☆╮ is a open source and community contributions are essential to project success!
- <TextField>, my new CMS project designed by a passionate developer, for developers!
- My last project Fast⚡︎CMS, a Flat-File cms.
- I am currently busy 😫.
Remove this on the $periods array():
Yes i don't understant what don't quote parsed... Work great in the [doc page](https://flatboard.org/view.php/plugin/page/p/docs) plugin.
For the quick reply is ready no? The form appear in accordeon style with jQuery.
, 3600 => 'h', 60 => 'm', 1 => 's'
Yes i don't understant what don't quote parsed... Work great in the [doc page](https://flatboard.org/view.php/plugin/page/p/docs) plugin.
For the quick reply is ready no? The form appear in accordeon style with jQuery.
- Before ask a question, read the documentation.
- 🎉 Featured as #1 product of the day on Product Hunt
- Please like in alternativeto.net 👍🏻
- ╰☆╮Flatboard╰☆╮ is a open source and community contributions are essential to project success!
- <TextField>, my new CMS project designed by a passionate developer, for developers!
- My last project Fast⚡︎CMS, a Flat-File cms.
- I am currently busy 😫.
Suggested Topics
SurveyBuilder-Admin
started todolist My Project(WebPress) - CMS+Forum-script
Open Bar
Cyrille BORNE
started 🇫🇷 solved BBCode in /lib/Parser.lib.php on line 131
International Discussions
SurveyBuilder-Admin
started plugin Mention - plugin
Resources
492da5
started IP's and Admin or Moderator control pannel
Feature Requests