Jump to content

Convert timestamp to date in template.


Recommended Posts

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}}
Returns other stuff if there's no timestamp on record

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);}}


Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 months later...
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.

Link to comment
Share on other sites

  • 3 weeks later...


This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...