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
Thanks, Erin
Re: [erinm356] Dates before 1900 not displaying correctly
By ross - April 14, 2009
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
Re: [erinm356] Dates before 1900 not displaying correctly
By Dave - April 14, 2009
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!
interactivetools.com
Re: [Dave] Dates before 1900 not displaying correctly
By erinm356 - April 14, 2009 - edited: April 14, 2009
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: </span><?php echo $veteran_registryRecord['born'] ?><br />
<?php endif ?>
<?php if ($veteran_registryRecord['died'] != '1800-01-01 00:00:00'): ?>
<span id="vetHeading">Died: </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: </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: </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
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.
interactivetools.com
Re: [Dave] Dates before 1900 not displaying correctly
By erinm356 - April 15, 2009
Thank you, Erin
Re: [Dave] Dates before 1900 not displaying correctly
By Mikey - December 13, 2010
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: [zick] Dates before 1900 not displaying correctly
By Chris - December 13, 2010
The field name shouldn't matter. I believe the above solution should work for you.
Have you tried simply outputting <?php echo $veteran_registryRecord['date'] ?>? Do you get a date like this: 1837-06-21 00:00:00?
What exactly happened when you gave it a try and it didn't work? I'm not sure I understand what a conflict would be.
Chris
Re: [chris] Dates before 1900 not displaying correctly
By Mikey - December 13, 2010
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!!!!