![]() |
Facebook-style date/time display helper? (RESOLVED) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Facebook-style date/time display helper? (RESOLVED) (/showthread.php?tid=21364) |
Facebook-style date/time display helper? (RESOLVED) - El Forum - 08-07-2009 [eluser]IsaacS[/eluser] Hi everyone, Does anyone know of an extension to the Date helper in CodeIgniter that allows for Facebook style dates? eg: Just now/a moment ago 1 hour ago 2 days ago 5 months ago It would be even lovelier if it was customisable, and utterly cliché-producing if it could do things like fortnights ![]() I've had a look on Google, but there's only lots of rubbish that comes up, which makes finding this helper a right pain. I'm hoping that the Date helper has this built in, and I just haven't noticed? Thanks! Isaac Facebook-style date/time display helper? (RESOLVED) - El Forum - 08-07-2009 [eluser]Pascal Kriete[/eluser] The timespan function in the date helper should get pretty close. You can always split the string at the commas if you don't want the whole thing. It doesn't do fortnights, but those could be added without too much effort - the code is pretty straightforward. Start with the largest one and work your way down. Facebook-style date/time display helper? (RESOLVED) - El Forum - 08-07-2009 [eluser]IsaacS[/eluser] OK, I'll give it a go. Thanks, Isaac Facebook-style date/time display helper? (RESOLVED) - El Forum - 08-07-2009 [eluser]helmutbjorg[/eluser] This uses the standard language files too... I'm sure you could modify it to say 'a moment ago' if below a minute or so.. MY_date_helper.php Code: /** Usage Code: echo difference('21546215621'); // Outputs: 2 minutes Facebook-style date/time display helper? (RESOLVED) - El Forum - 08-08-2009 [eluser]Johan André[/eluser] I did this a while ago: http://ellislab.com/forums/viewthread/106557/ Not the best, but works... Facebook-style date/time display helper? (RESOLVED) - El Forum - 08-08-2009 [eluser]alxjvr[/eluser] i use the ff. as a helper function, not quite elegant, but it works for my needs as well. Code: function days_ago($time = 1, $post = false, $lang) { Facebook-style date/time display helper? (RESOLVED) - El Forum - 08-08-2009 [eluser]IsaacS[/eluser] Thanks alxjvr, but I'm using a slightly modified version of Johan André's script in the link above, so this thread is now resolved. Thanks again to all of you who've helped out on this - makes me love CI even more seeing how helpful everyone is! Isaac |