Dates before 1900 not displaying correctly

10 posts by 5 authors in: Forums > CMS Builder
Last Post: December 13, 2010   (RSS)

By erinm356 - April 13, 2009 - edited: April 13, 2009

I am working on setting up CMS Builder on the site of a National Military Museum & Memorial Hall. The site has some sections where details about veterans are listed. Some of the fields I added to this section are for the dates born, died and married. As this is a historical site, some of these dates occurred before 1900. I have noticed that for every date before 1900, it is displayed as Dec 31, 1969, although it is being stored correctly in the database. Can anyone explain why this is happening and what I might do to fix it?

Thanks, Erin

Re: [erinm356] Dates before 1900 not displaying correctly

By ross - April 14, 2009

Hi Erin

Are you using the latest version of CMS Builder? I'll do some testing for you to see what's happening but it would best if I do it with the same version as you :).

Let me know and we'll go from there. Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Dates before 1900 not displaying correctly

By erinm356 - April 14, 2009

I am using version 1.27 (just installed within the last couple of weeks). I see that 1.28 just came out last week. Do you recommend that I update it?

Re: [erinm356] Dates before 1900 not displaying correctly

By Dave - April 14, 2009

Hi Erin,

The problem is some of the PHP functions for converting dates from one format to another don't support dates before 1970.

If the format isn't important you could just show the default date like this (change variable and field names as needed):
Date: <?php echo $record['date'] ?><br/>

And that would show something like this: 1899-02-09 15:00:27

If you need something more we'll need to look into what other PHP date function are available that support older dates. Can you let us know which version of PHP you have and what format you need it displayed in? (or if the default format above works?) Thanks.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Dates before 1900 not displaying correctly

By erinm356 - April 14, 2009 - edited: April 14, 2009

Thanks for the reply, Dave.

I'm using PHP 5.2.9.9.

I have to admit I don't particularly like just displaying the field as is, especially since the time will always be 00:00:00. There are several date formats that I wouldn't mind using. Currently, I have the format like Dec 31, 1969.

You can view the page here: http://www.soldiersandsailorsmuseum.org/veteran-registry-detail-test.php?Adams-1. On this test page, the first date is the field displayed directly out of the database, and the other two are formatted.

The code I'm using for this is (from the Born heading to the Married heading):
<?php if ($veteran_registryRecord['born'] != '1800-01-01 00:00:00'): ?>
<span id="vetHeading">Born:&nbsp;&nbsp;</span><?php echo $veteran_registryRecord['born'] ?><br />
<?php endif ?>
<?php if ($veteran_registryRecord['died'] != '1800-01-01 00:00:00'): ?>
<span id="vetHeading">Died:&nbsp;&nbsp;</span><?php echo date("M j, Y", strtotime($veteran_registryRecord['died'])) ?><br />
<?php endif ?>
<?php if ($veteran_registryRecord['burial_location']): ?>
<span id="vetHeading">Burial Location:&nbsp;&nbsp;</span><?php echo $veteran_registryRecord['burial_location'] ?><br />
<?php endif ?>
<?php if ($veteran_registryRecord['married_date'] != '1800-01-01 00:00:00'): ?>
<span id="vetHeading">Married:&nbsp;&nbsp;</span>
<?php echo date("M j, Y", strtotime($veteran_registryRecord['married_date'])) ?>
<?php if ($veteran_registryRecord['spouse']): ?> to <?php echo $veteran_registryRecord['spouse'] ?><?php endif ?>
<br />
<?php endif ?>

Thanks, Erin

Re: [erinm356] Dates before 1900 not displaying correctly

By Dave - April 15, 2009

Hi Erin,

The simplest way to do it is to just write a function to format the mysql date the way you want. Try this one. Add it near the top of the page:

<?php

// return mysql format date "1899-02-09 15:00:27" in this format "Dec 31, 1969"
function formatMysqlDate($mysqlDate) {
list($year, $monthNum, $zeroPaddedDay) = preg_split("/[- ]/", $mysqlDate);
$shortMonthName = date('M', mktime(0,0,0,$monthNum,1));
$longMonthName = date('F', mktime(0,0,0,$monthNum,1));
$dayNum = (int) $zeroPaddedDay;

echo "$shortMonthName $dayNum, $year";
}

?>


You can call it like this:
<?php formatMysqlDate($veteran_registryRecord['born']) ?>

Hope that helps! Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Dates before 1900 not displaying correctly

By erinm356 - April 15, 2009

Dave, that is amazing. Works like a charm! You guys are the best.

Thank you, Erin

Re: [Dave] Dates before 1900 not displaying correctly

By Mikey - December 13, 2010

Dave,
I need to set my dates back to the 1800s for historical photographs. The problem I have is that I already have about 80 photos loaded with the dates applied using the "date" section field.

Is it possible to implement your solution:
<?php formatMysqlDate($veteran_registryRecord['born']) ?>

using the "date" field like seen below:
<?php formatMysqlDate($veteran_registryRecord['date']) ?>

I gave it try before posting this reply and it didn't work. I didn't expect it too, since it seemed to create a conflict with the 'date'.

Do you have any suggestions how I could get older dates past 1969 to work? Would it work if I changed the field name from 'date' to something else? I guess if I changed the 'date' field name, then I'd still have to edit every photo's date that has been uploaded too. Is that correct?

Thanks for any light you can shed on this.
Zick

Re: [chris] Dates before 1900 not displaying correctly

By Mikey - December 13, 2010

Chris... you're right, it should for me. I spaced last night and tried placing <?php formatMysqlDate($galleryRecord['date']) ?> on a list page. Obvious where my mistake was now.

So now, I have <?php formatMysqlDate($record['date']) ?> working perfectly on my list page and <?php formatMysqlDate($galleryRecord['date']) ?> works like a charm on my details page.

Thanks!!!!