Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: 18 January 2038

  1. #1
    New Coder
    Join Date
    Aug 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    18 January 2038

    I am working on a project to put a local church burial records onto the web.

    We have used php and MYSql.

    Our problem is that dates between approx 01 January 1875 and 31 December 1899 which have be input are displayed in searches as 18 January 2038 (more specifically 18/01/2038).

    I realise that this date is significant and that the web servers are unix.

    When using a mysql browser I can see that the dates are stored looking correct, but cannot figure out how to get them to display correctly in php.

    Does anyone have any suggestions please.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    input your dates in the format yyyymmdd and make the column type DATE. Use DATE_FORMAT (see the mysql manual for that) to display your dates as you grab them out of mysql. Don't bother trying to format them with php.

    See the article in my links below if you have your dates in varchar/char format. It will tell you how to swap them around to the proper date type.

  • #3
    New Coder
    Join Date
    Aug 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the suggestion, however, the field is already a date field. It is only dates in the range quoted in my first posting that give problems. Are there any other suggestions?

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    if it is a date field it can hold dates between 1000 A.D. and 9999 A.D. so you may not be entering them correctly or something. Can you look at the data directly in mysql? Perhaps the issue is you are trying to format them in PHP and that is throwing things off?

  • #5
    New Coder
    Join Date
    Aug 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    THose dates are well within the needed range, the earliest that anyone was buried in our churchyard was 1845.

    The code to do the display of the date of burial is:

    <?php if (!isset($x_DateBurial)) { echo "<FONT color=FF0000>Unknown</FONT>"; } else { echo FormatDateTime($x_DateBurial,7); } ?>

    If I change the else bit to echo $x_DateBurial then the date is correct (displayed as ccyy-mm-dd) so it looks as though your suggestion that the PHP formatting is somehow unpsetting the display.

    I guess that somehow I have to manipulate $x_DateBurial into a new variable so that it displays as the average person in England would like to see it, ie dd/mm/ccyy. Can you suggest an easy way of doing this?

  • #6
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Use DATE_FORMAT when you are bringing the values out of your database, don't use PHP to format them only to display your results from your database.

    Code:
    select
    foo,
    bar,
    qux,
    date_format(datecolumn,'%d/%m/%Y') as BritishDate
    from yourtable

  • #7
    New Coder
    Join Date
    Aug 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many thanks, all working now.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •