kotaco Posted March 29, 2016 Posted March 29, 2016 I am trying to convert a timestamp that is recorded when a member joins a certain group to a Month/Date/Year format output in a block template. The code I have to display the timestamp is as follows: {{$joined = $member->r_spartac_join_date;}} {{if $member->r_spartac_join_date}} {$joined} {{else}} Returns other stuff if there's no timestamp on record {{endif}} The above works well to display the timestamp, but how do I go about converting the time stamp to M/D/Y format? I tried just wrapping the date function in tags, but it doesn't work: {{date("m-d-Y", $joined);}}
kotaco Posted March 30, 2016 Author Posted March 30, 2016 5 hours ago, Ryan Ashbrook said: {datetime="$joined"} Thank you sir. Just curious, is there any way to format that? For example it's showing "18 March" can that be changed to March 18, 2016 easily?
Ryan Ashbrook Posted March 31, 2016 Posted March 31, 2016 Hmm... not using the datetime output plugin, no. You can optionally do this: {datetime="$joined" dateonly="true"} However that will return a format of 03/17/2016. You could also do something like this: {expression="(string) \IPS\DateTime::ts( $joined )->strFormat( '%B %d, %Y' )"} Which will do what you're looking for. The parameters accepted in strFormat (to format the date) are the same as the strftime PHP function. So you can swap around the %B, %d, etc. however you like to format the date.
Tactical Geeks Posted July 26, 2016 Posted July 26, 2016 i stumbled upon this im tring to take the joined data and display the time between them (tenure) {expression="\IPS\DateTime::ts( $member->joined )->strFormat( '%B %d, %Y' )"} tried this but no luck how would it do this?
TSP Posted July 29, 2016 Posted July 29, 2016 On 26.7.2016 at 5:09 AM, veteran365 said: i stumbled upon this im tring to take the joined data and display the time between them (tenure) {expression="\IPS\DateTime::ts( $member->joined )->strFormat( '%B %d, %Y' )"} tried this but no luck how would it do this? What do you get when using that code and what do you expect? If you need to know the difference in terms of number of days or similar between two dates, then that would of course require entirely different code.
Tactical Geeks Posted July 29, 2016 Posted July 29, 2016 I'm trying to take the joined date and display time between the two. In format of x days, x months, x years so if my join data was 2/25/14 it would show as 4 days, 4 months , 2 years
Tactical Geeks Posted August 16, 2016 Posted August 16, 2016 did it $member = \IPS\Member::loggedIn(); $datetime1 = $member->joined; $datetime2 = new DateTime(); $interval = $datetime1->diff($datetime2); echo $interval->format('%d Days, %m months, %y Years'); posting here incase someone else needs to do this
Recommended Posts
Archived
This topic is now archived and is closed to further replies.