We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27072
    • 76 Posts
    Hello,

    In snippet #1 I initialized a placeholder DOB (date of birth) with a date value from the database.
    $modx->setPlaceholder('DOB', $result['DOB']);


    In snippet #2 I’m trying to explode the value of this placeholder:
    $dob = '[+DOB+]';
    list($year, $month, $day) = explode('-', $dob);
    $year = $dob[0];
    $month = $dob[1];
    $day = $dob[2];
    
    // I also tried: list($year, $month, $day) = split('[/.-]', $dob);

    The results are:
    echo ’[+DOB+]’ -> 1982-12-02
    echo $dob -> 1982-12-02
    echo $year -> 1982-12-02
    echo $month -> blank
    echo $day -> blank

    Everything works as expected when I substitute the date value from the database with a constant "1982-12-02"

    I’ve also tried many variations of date manipulation (of either the original DB query or the placeholder) via PHP’s date() function - such as in: $year = date(’Y’, $dob), but each time I use date(), the error message below is received. I’ve looked at MODx docs and wiki for solutions but couldn’t make head from tail.

    MODx encountered the following error while attempting to parse the requested resource:
    « Execution of a query to the database failed - Incorrect integer value: \'\' for column \'user\' at row 1 »
    SQL: INSERT INTO `celebrities`.`modx_event_log` (eventid,type,createdon,source,description,user) VALUES(1,3,1235644591,\'love-horoscope - Snippet\',\'date() [function.date]: It is not safe to rely on the system\\\'s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \\\'Europe/Helsinki\\\' for \\\'2.0/no DST\\\' instead

    Please help me to figure out what I am missing here.

    Thanks a lot.
      Cheers,
      Shlomo Tommer
      • 27072
      • 76 Posts
      All I had to do is to convert the stored date into a valid UNIX timestamp format:
      $dob = date("Y-m-d", strtotime('[+DOB+]'));
      $day = date('d', $dob);
      $month = date('m', $dob);
      $year = date('Y', $dob);
        Cheers,
        Shlomo Tommer
        • 7231
        • 4,205 Posts
        Glad you got it working.

        As for the original problem. I would try defining the array first then use list to make sure it is doing what I expect:
        $z = explode('-', $dob);
        list($year, $month, $day) = $z;
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 27072
          • 76 Posts
          Quote from: dev_cw at Feb 26, 2009, 07:16 AM

          Glad you got it working.

          As for the original problem. I would try defining the array first then use list to make sure it is doing what I expect:
          $z = explode('-', $dob);
          list($year, $month, $day) = $z;
          I love it. Even though I’ve never seen it before, it makes a lot of sense - integrity wise. Thanks.
            Cheers,
            Shlomo Tommer
            • 10487 MODX Staff
            • 1,535 Posts
            @schlomot: FYI, you will have problems accessing the placeholder like this:
            $dob = '[+DOB+]';

            Instead, you should use:
            $dob = $modx->getPlaceholder('DOB');

            The strtotime() function is most likely not giving you the desired date you are looking for. Echoing the $dob output will give the correct date only because MODx is dynamically parsing the placeholder value on the page wink
              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com
              • 27072
              • 76 Posts
              Quote from: garryn at Feb 26, 2009, 08:46 AM

              @schlomot: FYI, you will have problems accessing the placeholder like this:
              $dob = '[+DOB+]';
              Instead, you should use:
              $dob = $modx->getPlaceholder('DOB');

              The strtotime() function is most likely not giving you the desired date you are looking for. Echoing the $dob output will give the correct date only because MODx is dynamically parsing the placeholder value on the page wink
              Thank you so much. DONE!!!
                Cheers,
                Shlomo Tommer