<![CDATA[ Date of Birth & Updateprofile - MODX Community Forums]]> https://forums.modx.com/thread/?thread=44846 <![CDATA[Re: Date of Birth & Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=3#dis-post-542099
https://gist.github.com/dubrod/348bde79ce906aaedbd0f2e73ee0b0a5]]>
dubrod Jun 01, 2016, 01:18 PM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=3#dis-post-542099
<![CDATA[Re: Date of Birth &amp; Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257978 ]]> jobkingori Jun 06, 2011, 04:41 AM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257978 <![CDATA[Re: Date of Birth &amp; Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257977
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.]]>
Kristoffer May 31, 2011, 05:53 AM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257977
<![CDATA[Re: Date of Birth &amp; Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257976
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.
]]>
BobRay Apr 28, 2011, 01:45 PM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257976
<![CDATA[Re: Date of Birth &amp; Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257975
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.)]]>
jobkingori Apr 28, 2011, 09:23 AM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257975
<![CDATA[Re: Date of Birth &amp; Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257974
[[+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





]]>
Reconix Feb 12, 2011, 05:28 PM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257974
<![CDATA[Re: Date of Birth &amp; Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257973 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]]>
boomerang Feb 12, 2011, 04:46 PM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257973
<![CDATA[Re: Date of Birth &amp; Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257972

Here are a couple more things to try:

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

[[+dob:strtotime:date=`%d-%m-%Y`]]
]]>
BobRay Feb 12, 2011, 12:31 PM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257972
<![CDATA[Re: Date of Birth &amp; Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257971 sottwell Feb 12, 2011, 09:17 AM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257971 <![CDATA[Re: Date of Birth &amp; Updateprofile]]> https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257970 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]]>
boomerang Feb 12, 2011, 08:41 AM https://forums.modx.com/thread/44846/date-of-birth-updateprofile?page=2#dis-post-257970