1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.1 XenForo Date Question from a Custom User Field

Discussion in 'XenForo Questions and Support' started by robdog, Nov 9, 2011.

  1. robdog

    robdog Well-Known Member

    I have a user field that asks the user "Fan Since:" and they have to enter a date like 2010-10-04.

    I want to pass that into this function or something similar to that:
    {xen:date $user.customFields.packer_fan_since}

    But that appears to want a timestamp. Is there a date format function that takes YYYY-MM-DD in XenForo Templates?

    Thanks.
     
  2. James

    James Well-Known Member

    I think all the XenForo templates take Unix timestamps. Why not specify a PHP callback that handles the date and converts it to a timestamp.
     
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    The purpose of the date function is to extract a readable date from a timestamp. You already have a readable date (2010-10-04 in your example). Did you want to change it to a different format or something?

    This is the function you want:

    http://us3.php.net/manual/en/function.strtotime.php

    But strtotime() is not available to the templates. You can do it with an addon.
     
  4. robdog

    robdog Well-Known Member

    I thought the call backs were only for validation. You can convert the data within the callback for custom user fields? Because if that is the case, I am golden.
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    What do you want to accomplish with your custom field? Which template are you working in? You likely wouldn't define a callback for the custom field. Rather you would create an appropriate listener to perform the date operation where it's needed in the templates.
     
  6. robdog

    robdog Well-Known Member

    Basically I trying to have the users input a date (2011-10-01) and convert it to a timestamp when it is saved into the DB so it can be used in the <xen:date /> template command. However, this would not work, because editing that value again would need to convert from timestamp to YYYY-MM-DD. So to simplify the process, I just had them input a 4 digit year, lol.
     

Share This Page