We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Parse a segment of the URL as a date

Development and Programming

LuCmf's avatar
LuCmf
6 posts
13 years ago
LuCmf's avatar LuCmf

Hi,

I’m currently developing a part of a site in which the article detail URL looks like this: site.com/{entry_date format='%l_%F_%d_%Y'}

In the detail template I need to parse that segment as a date so I can use is as the entry_date to show the entry of the URL.

Something like: {exp:channel:entries channel="articles" search:entry_date="{segment_2}”}

This won’t work because the entry_date is in unix format.

Any ideas?

Thanks! Lu

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Hi LuCmf,

I don’t think, you can achieve proper output using this tag. Either change the date format in URL (lile day/month/year or unix-timestamp) or use PHP in your template.

You can use PHP in template as below :

<?php
$ee =& get_instance();
$seg2 = $ee->uri->segments[2];
$date_arr = explode('_', $seg2);
$date = $date_arr[2].' '.$date_arr[1].' '.$date_arr[3];
$utime = strtotime($date);
?>
{exp:channel:entries channel="articles" search:entry_date="<?php echo $utime; ?>"}

you can use year, month, day parameters of channel entry tags also:

<?php
$ee =& get_instance();
$seg2 = $ee->uri->segments[2];
$date_arr = explode('_', $seg2);
$date = $date_arr[2].' '.$date_arr[1].' '.$date_arr[3];
$utime = strtotime($date);

$day = $date_arr[2];
$month = date('m', $utime);
$year = $date_arr[3];
?>
{exp:channel:entries channel="articles" day="<?php echo $day; ?>" month="<?php echo $month; ?>" year="<?php echo $year; ?>"}

(Please note: all the code isn’t tested)

Use Template preferences as Allow PHP?:Yes, PHP Parsing Stage:Input

Hope this would help you.

Best Regards,

       
LuCmf's avatar
LuCmf
6 posts
13 years ago
LuCmf's avatar LuCmf

Hi Bhashkar,

Thanks a lot for your help,

I tried the month, day, year version and it works great!

Thanks!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.