I see that some people are having trouble with displaying the [[+dob]] field when using [[Profile]] or such implementation of the [[Login]] system. I too, had problems.
Some folks here might be wondering what the numbers being displayed when they use [[+dob]] placeholder mean. "Huh? That’s not my birthday" might you say -- Well in fact, it is...
The way modx stores dates is different than what you might already know. Modx stores dates and time as
Unix timestamp wich makes calculation between 2 dates (and hours, minutes, seconds for that matter) less complicated than any other system because when using
Unix timestamp, date comparison is actually as simple as comparing 2 variables. There’s not much more to it... just a "timestamp" related to a previous date in history.
If i haven’t made myself clear, and surely i wasn’t clear -- that’s me -- here’s some more detailed information about the situation;
According to
http://www.unixtimestamp.com/;
What is the unix time stamp?
The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch. This is very useful to computer systems for tracking and sorting dated information in dynamic and distributed applications both online and client side.
What happens on January 19, 2038?
On this date the Unix Time Stamp will cease to work due to a 32-bit overflow. Before this moment millions of applications will need to either adopt a new convention for time stamps or be migrated to 64-bit systems which will buy the time stamp a "bit" more time.
Hopefuly, you’ve understood what Unix timestamp is all about now; seconds that have passed since a predetermined date - January 1st, 1970.
That still leaves us with a problem; correctly displaying the date under Modx ([[+dob]] in this case).
I have written a very simple snippet that you can freely use to get you out of trouble in case you need to display the date in a human-readable format.
First of all, create a snippet and call it ’dateFix’ - or any other name really, you’re the webmaster - then copy the following code into it;
<?php
// Set error message in case all hells break loose
$output = '&timeStamp patameter not set!';
// Declare the paramater value to the snippet, defaults to null if isn't set
$unixTimestamp = isset($timeStamp) ? $timeStamp : '';
// Check parameter value - if not empty then
if (!empty($unixTimestamp)) {
// Define snippet output value to a human-readable date converted timestamp
// You can adjust the display output by modifying the 'y/m/d' portion of the code according to your region or preference
// See php function date() for more options
$output = date('y/m/d', $unixTimestamp);
}
return $output;
What this actually does, even tho pretty well commented as it is, is take your inputed timestamp and convert it to a human-readable date format, of your liking. (see php date() function for more information on output options)
Now, i’ve got to call this snippet somehow and make it useable for my needs.
Wherever you need a timestamp converted, in this case in the profile template for our user, you caan just call it using;
[[!dateFix? ×tamp=`timeStampCode`]]
or, to be case specific;
[[!dateFix? ×tamp=`[[+dob]]`]]
This little script will output a human readable date whenever you neet it.
Hope it serves a purpose - it does for me anyways!
Thanks