Folks;
as I haven't found good starters here, are there any recommendations on how to make best use of dates in bludit? Like, in example, I'd enjoy adding a "this day <xx> years ago" section, or limit my starting page only to posts from the last <n> days. Is that something that can be achieved the way bludit stores its (meta)data? Any good pointers on that?
Thanks in advance and best regards,
Kristian
Handling calendar / date in pages?
- Misteric
- Ssr. Bludit
- Posts: 18
- Joined: Mon Aug 08, 2022 2:55 pm
- Location: Brussels, Belgium
- Has thanked: 14 times
- Been thanked: 9 times
Hi Kristian,
To show how many minutes and days are past, you can use the php-code below:
I hope it's helpfull!
Misteric
To show how many minutes and days are past, you can use the php-code below:
Code: Select all
<?php
function timeBetween($start_date,$end_date)
{
$diff = $end_date-$start_date;
$seconds = 0;
$hours = 0;
$minutes = 0;
if($diff % 86400 <= 0){$days = $diff / 86400;} // 86,400 seconds in a day
if($diff % 86400 > 0)
{
$rest = ($diff % 86400);
$days = ($diff - $rest) / 86400;
if($rest % 3600 > 0)
{
$rest1 = ($rest % 3600);
$hours = ($rest - $rest1) / 3600;
if($rest1 % 60 > 0)
{
$rest2 = ($rest1 % 60);
$minutes = ($rest1 - $rest2) / 60;
$seconds = $rest2;
}
else{$minutes = $rest1 / 60;}
}
else{$hours = $rest / 3600;}
}
if($days > 0){$days = $days.' days, ';}
else{$days = false;}
if($hours > 0){$hours = $hours.' hours, ';}
else{$hours = false;}
if($minutes > 0){$minutes = $minutes.' minutes, ';}
else{$minutes = false;}
$seconds = $seconds.' seconds';
return $days.''.$hours.''.$minutes.''.$seconds;
}
echo timeBetween(strtotime($page->date()), strtotime(date("Y-m-d H:i:s")));
?>
Misteric
-
kr428
- Sr. Bludit
- Posts: 45
- Joined: Thu Jan 05, 2023 9:07 pm
- Has thanked: 14 times
- Been thanked: 4 times
Thanks, definitely so.Misteric wrote: Tue Apr 09, 2024 3:37 pm Hi Kristian,
To show how many minutes and days are past, you can use the php-code below:
//..//
I hope it's helpfull!
Misteric
- Misteric
- Ssr. Bludit
- Posts: 18
- Joined: Mon Aug 08, 2022 2:55 pm
- Location: Brussels, Belgium
- Has thanked: 14 times
- Been thanked: 9 times
Kristian
You have the creation date and the Modified day:
with an if statement like this:
(You can change the year 2024 in the if-statement with a variable.)
Misteric
You have the creation date and the Modified day:
with an if statement like this:
Code: Select all
<?php
$date = $page->date();
if(isset($page->dateModified())) {
$date = $page->dateModified();
}
if(strtotime($date) > strtotime(date("2024-10-31 23:59:59"))) {
echo timeBetween(strtotime($date), strtotime(date("Y-m-d H:i:s")));
}
?>
Misteric
-
kr428
- Sr. Bludit
- Posts: 45
- Joined: Thu Jan 05, 2023 9:07 pm
- Has thanked: 14 times
- Been thanked: 4 times
Ah, ok, so I basically have to iterate across all pages and compare dates with "today"? Won't that fall over performance-wise if the site gets a bit ... bigger? Or am I getting something wrong here? From a database point of view, what I'm looking for is something like "give me all pages created on $day-of-month / $month-of-year regardless of which year".
(This snippet, though, scratches another itch I was having for quite a while, so thanks for that.
)
(This snippet, though, scratches another itch I was having for quite a while, so thanks for that.

