We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38783
    • 571 Posts
    When a new user is created the default entry for the date of birth field is: 0

    In MODX 2.5.x if you had a new user who had not yet entered anything into their date of birth field the this code would result in an empty entry on the page (which is what I would like to see).

    [[!+dob:date=`%d-%m-%Y`]]


    Since updating to MODX version 2.6.5 the same code returns 01-01-1970 which is technically correct, in that the Unix timestamp says that zero is 01-01-1970. But this is not what I want to see!

    For a user who has not yet entered anything in their profile for date of birth it is a little odd for them to see 01-01-1970. So I would like to revert to the previous behavior where nothing is displayed.

    Does anyone know how I can do this?

    I would prefer not to have write snippet that converts 01-01-1970 to 'nothing' because one day someone may register on the site who was born on 01-01-1970 and their date of birth will then cause me problems!

    PHP version 7.2.6 was used for both the 2.5.x and 2.6.5 versions of the MODX site in question. [ed. note: andytough last edited this post 5 years, 9 months ago.]
      If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

      email: [email protected] | website: https://andytough.com
      • 38783
      • 571 Posts
      As a follow up, I have got around this by using

      [[!+dob:notequalto=`0`:then=`[[!+dob:date=`%d-%m-%Y`]]`]]


      Is there a better way to do this? [ed. note: andytough last edited this post 5 years, 9 months ago.]
        If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

        email: [email protected] | website: https://andytough.com
        • 3749
        • 24,544 Posts
        If this works, I think it might be slightly faster since the 'then' clause wouldn't have to be parsed and MODX won't look for an else clause:

        [[!+dob:notempty=`[[!+dob:date=`%d-%m-%Y`]]` ]]


        BTW, your example is missing this at the end, which might cause some confusion:

        ` ]]


          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
          • 38783
          • 571 Posts
          Thank you Bob. I will try that. I have modified my example.
            If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

            email: [email protected] | website: https://andytough.com
            • 10378
            • 375 Posts
            Quote from: andytough at Jul 21, 2018, 12:46 AM
            As a follow up, I have got around this by using

            [[!+dob:notequalto=`0`:then=`[[!+dob:date=`%d-%m-%Y`]]`]]


            Is there a better way to do this?

            But this will omit persons born on 1970-01-01

            I think the field should be NULL if no birth date was entered.

            I posted this issue on GitHub a some times ago but the ticket was closed:
            https://github.com/modxcms/revolution/issues/11873#issuecomment-51103547
              Freelancer @bitego http://www.bitego.com
              ---
              GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
              More infos here: http://www.bitego.com/extras/goodnews/
              • 3749
              • 24,544 Posts
              Quote from: gadgetto at Jul 21, 2018, 03:25 PM
              Quote from: andytough at Jul 21, 2018, 12:46 AM

              I think the field should be NULL if no birth date was entered.

              I think MySQL will throw an error when you try to save their data. Also, the field is currently set to not allow null. Even if you changed that, I think MySQL will still reject it for a date field.

              MySQL date fields can hold dates back to 1001 AD. I notice that the xPDOObject has code that processes a PHP DateTime object, so my guess is that everything is fine except when we try to store a blank value.

              I think you could use a plugin attached to OnUserProfileBeforeSave that converts the dob field value to 999999999 if the dob field is empty, and then check for that value when you display a dob. I think at that point, the dob field for users born 1970-01-01 would be a non-empty string (easy to check with this in your plugin when submitting a user with a dob of 1970-01-01):

              $modx->log('modX::LOG_LEVEL_ERROR, 'DOB: ' . $userprofile->get('dob'));


                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