We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24687
    • 14 Posts
    Quote from: Muggins at Feb 12, 2011, 10:38 AM

    Nope tried those options and doesn’t return anything. huh

    Did try the following too:
    [[+dob:date=`%d %b %Y`]] or [[+dob:date=`%d %m %Y`]]

    But no joy yet.

    What does you’re php code look like for that ?
    • Hi there, I’m trying to call your a User’s account the [[+dob]] which is listed here http://rtfm.modx.com/display/revolution20/Users but when I enter the date in the Manager what is returned on my Profile page (front end) is this -149130000.

      I’m no expert with php and I’ve simply used what is available within the Profile and UpDateProfile snippets.

      But thanks for your help
        Helen Warner
        Number one pixel!
        Proud to be linked with MODX at Crimson Pixel
      • That looks like a UNIX timestamp (the negative number indicates that the date is some time before 1970). The date filter should be converting that to a human-readable date.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 3749
          • 24,544 Posts
          I hate working with dates. wink

          Here are a couple more things to try:

          [[+dob:strftime=``%d-%m-%Y`]]
          
          [[+dob:strtotime:date=`%d-%m-%Y`]]
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
          • Tried those too, without success, very baffling. huh Especially when all other fields listed in Users seem to work.

            Came across this whilst trawling for a solution and it seems there may be a bug!

            http://modxcms.com/forums/index.php/topic,59175.0.html
              Helen Warner
              Number one pixel!
              Proud to be linked with MODX at Crimson Pixel
              • 24687
              • 14 Posts
              What I think every one was actually looking for was:
              [[+userId:userinfo=`dob`:date=`%d,%m,%Y`]]
              



              --
              I could be totally wrong here as I haven’t tried this but as a work around you could do;

              $profile = $modx->user->getOne('Profile');
              return $profile ? $profile->get('dob') : '';
              


              --
              Ok I done the basic profile page, I actually spent the hole of yesterday merely creating my own system to realise that some one had already beat me to it and made a better one. grr, I did have a good learning curve though !

              Using the login addon for rev, here’s how I done it using code examples from the documentation. ( Custom Fields )
              <label for="dateofbirth">Date of Birth:
              <span class="error">[[+error.dateofbirth]]</span>
              </label>
              <input type="text" name="dateofbirth" value="[[+dateofbirth]]" />
              


              So on the profile page use value

              [[!Profile]]
              Date Of Birth: [[+dateofbirth]]
              


              Then updating that,
              [[!UpdateProfile]]
              <label for="dateofbirth">Date of Birth:
              <span class="error">[[+error.dateofbirth]]</span>
              </label>
              <input type="text" name="dateofbirth" value="[[+dateofbirth]]" />
              


              For my site I done pretty much the same only included the jq datepicker





                • 14372
                • 49 Posts
                So I don’t think that there’s any bug ... BUT I think we just have to first understand what’s happening.

                The modx guys implemented the [[+dob]] field with timestamps instead of a date string and most of us expect it to work with date strings hence the frustration. Which means that when you enter the data into the field, modx expects a timestamp rather than a date string and if you edit using the backend, the calendar widget also converts your date into a timestamp, even though it gave you a user friendly way of choosing a date but feeding a timestamp.

                For those who don’t know what a timestamp is I found a good explanations here; http://www.go4expert.com/forums/showthread.php?t=3595

                Unix time, or POSIX time, is a system for describing points in time. It is widely used not only on Unix-like operating systems but in many other computing systems, including the Java programming language. It is an encoding of UTC, and is sufficiently similar to a linear representation of the passage of time that it is frequently mistaken for one.
                
                The Unix timestamp is widely used in PHP. [color=red]It is the amount of seconds between January 1st 1970 00:00:00 (Unix Epoch) and the present time, to the closest second.[/color] As you can imagine, after over 35 years it is now quite a big number!
                
                Unix time is one of the things is handled differently on Windows servers compared to *nix servers. On a Linux server [color=red]the timestamp can be positive or negative, representing before and after the Unix Epoch.[/color] Windows servers however produces -1 instead of a negative timestamp, or in PHP 5.1, it produces false.


                So now realising whats happening who has an idea of how we can format the timestamp when reading it ... I thought of using output modifiers but theoretically that solves only one part of the problem and so far.

                For output modifiers check here; http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+(Output+Modifiers)

                Date formats with modx check here; http://rtfm.modx.com/display/revolution20/Date+Formats

                PHP has to functions for what we are trying to do though

                • strtotime - converts date string to a timestamp
                • strftime - converts timestamp to date string

                As an alternative to PHP stuff Modx provides output modifiers (see link above), which can help you when reading the timestamp from the [[+dob]] field to an appropriate representation. At least that should handle the reading part.

                To input a value for [[+dob]] I did a test by feeding a timestamp into the [[+dob]] placeholder and VWALA! the backend got it right! smiley So if there is some way to let a user use a calendar selector that fills the input with a timestamp.

                Hope I’m making sense.

                So people...timestamps. (This shoulda been in the docs since its giving people hell, which makes me wonder if there is a way the modx guys can help us out. Coz they are the ones who made the rules. Without the rules in the docs, we are flying blind.)
                  • 3749
                  • 24,544 Posts
                  If you want a datepicker (calendar widget) in the front end, it’s possible to use ExtJS (which MODX uses in the Manager), but I found it easier to use another system. Take a look at the code of the NewsPublisher snippet, which provides a datepicker for date TVs.

                  The NP datepicker is complicated by the fact that it allows the user to enter both the date and time. If you just want the date, it would be simpler.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 16348
                    • 64 Posts
                    Here is how I have solved this problem. I’m using Login and this solution works both with Register and UpdateProfile (the following code is for UpdateProfile).

                    Here is the relevant part of my UpdateProfile form chunk:
                    [[+error.dob]]<label for="dob">[[!%login.dob]]:</label>
                    <input type="text" name="dob:required" id="dob" value="[[+dob:date=`%Y-%m-%d`]]" />


                    Here is my snippet call:
                    [[!UpdateProfile?
                      &preHooks=`formatDob`
                    ]]


                    Here is the code for the snippet formatDob used as a preHook:
                    <?php
                      $dob = $hook->getValue('dob');
                      $hook->setValue('dob',strtotime($dob));
                      return true;
                    ?>


                    I’m also using jQuery DatePicker on the page:
                    $( "#dob" ).datepicker({
                      dateFormat: 'yy-mm-dd',
                      changeMonth: true,
                      changeYear: true,
                      yearRange: "-110:+0",
                      maxDate: "0"
                    });


                    To summarize, the preHook takes the string passed from the datepicker and converts it to a timestamp before the profile is updated. For display, an output modifier (date) is working for me. This example should work without the datepicker if you don’t want that feature.
                      • 14372
                      • 49 Posts
                      I can confirm that this works ... PERFECTLY!!! smiley