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

Plugin: WI Friendlee Date - Convert supplied date parts to a friendly date output.

Development and Programming

Chad Crowell's avatar
Chad Crowell
242 posts
16 years ago
Chad Crowell's avatar Chad Crowell

As if there weren’t enough date based plugins… this is something I needed for a client. Could be useful in the right situations.

{exp:wi_friendlee_date m="month" d="date" y="year" h="hours" mn="minutes" s="seconds" display="php date codes"}

Place this tag in your code and replace month date year hours minutes seconds parameters in the code with any information to have the plugin return the date formatted nicely.

Only m, d and y are required. If no h, mn or s parameters are supplied, the plugin will not add hours, minutes or seconds into the generated date/time.

You can control the display that is output by entering typical PHP date formatting codes into the display parameter. See http://us2.php.net/date for all available options.

The default display, if you don’t supply a display parameter is MM/DD/YYYY.

Examples:

{exp:wi_friendlee_date m="6" d="24" y="1995"}

Output: 06/24/1995

{exp:wi_friendlee_date m="6" d="24" y="1995" h="9" mn="55" s="00"}

Output: 06/24/1995 09:55:00

{exp:wi_friendlee_date m="6" d="24" y="1995" display="D, F jS, Y"}

Output: Sat, June 24th, 1995

{exp:wi_friendlee_date m="6" d="24" y="1995" h="9" mn="55" s="00" display="D, F jS, Y, g:i:s"}

Output: Sat, June 24th, 1995, 9:55:00

{exp:wi_friendlee_date m="{segment_4}" d="{segment_5}" y="{segment_6}" display="D, F jS, Y"}

URL: www.mydomain.com/template_group/template/url_title/6/24/1995/ Output: Sat, June 24th, 1995

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
16 years ago
Sue Crocker's avatar Sue Crocker

Thanks for sharing, Chad. I can find a use for this.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi Chad,

There are at least two plugins having very similar functionality: Nice Date and Formatted Date.

       
Chad Crowell's avatar
Chad Crowell
242 posts
16 years ago
Chad Crowell's avatar Chad Crowell

Yes I know, but since I had written it, I figured some others may like it.

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
16 years ago
Leevi Graham's avatar Leevi Graham

Hey Chad,

I only wanted the month and year for my archive heading so I slightly modded your plugin. Basically I added some default options to the dat vars so mktime doesn’t break.

$m            = $TMPL->fetch_param('m') ? $TMPL->fetch_param('m') : 1;
$d            = $TMPL->fetch_param('d') ? $TMPL->fetch_param('d') : 1;
$y            = $TMPL->fetch_param('y') ? $TMPL->fetch_param('y') : 0;
$h            = $TMPL->fetch_param('h') ? $TMPL->fetch_param('h') : 0;
$mn            = $TMPL->fetch_param('mn') ? $TMPL->fetch_param('mn') : 0;
$s            = $TMPL->fetch_param('s') ? $TMPL->fetch_param('s') : 0;
$display    = $TMPL->fetch_param('display');

Then I scrapped the warning. Now I can do cool stuff like:

There were no posts published in {exp:wi_friendlee_date m="{segment_4}" y="{segment_3}" display="F Y"}
       
Chad Crowell's avatar
Chad Crowell
242 posts
16 years ago
Chad Crowell's avatar Chad Crowell

Sweet! I like when people smarter than me make my stuff even better. Feel free to branch the Git repo if you want.

       
kpow's avatar
kpow
22 posts
15 years ago
kpow's avatar kpow

Any idea if this plugin could be used in conjunction with the simple math plugin? (http://ellislab.com/forums/viewthread/110055/P36/#631282) I was trying to get a date calculated such as: I have a field (days) that has 10 (or 20 or ..) and I have a field for date such as 12/12/2009. I wanted to have the {date}+(days) output the result in a date format: 12/22/2009. is there a easy way to do such?

       

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.