Jump to content

Float, integer or text into date


BFD Calendar
 Share

Recommended Posts

I'm using three fields to calculate the date of an event, bfd_day, bfd_month and bfd_year. All are 'integer' fields. When 'bfd_year' is less than 100 the date turns into the 2000s. Cicero, died in 43bc suddenly died in 2043bc....

Would it make a difference if 'bfd_year' is a text or float field? And if so, will I keep all my data if I change the field from integer to text?

Here's what I use to calculate the date:

    $day = $page->bfd_day->title;
    $month = $page->bfd_month->title;
    $year = $page->bfd_year;
    $fulldate = new DateTime("$year-$month-$day");
    echo "{$fulldate->format("l jS \of F Y")}";
    if(trim($page->bfd_date_bc->title)=='bc') { echo "bc";
    }; 
	$thisyear = date("Y");
	if(trim($page->bfd_date_bc->title)=='bc') { echo $thisyear + $page->bfd_year . " years ago";
	} else { echo $thisyear - $page->bfd_year . " years ago";
	};

The 'years ago' calculation works fine, it says Cicero died 2056 years ago today.

Link to comment
Share on other sites

i guess what you're implying is that the year needs to have leading zeroes; like 0043;

maybe add leading zeroes to the year if it is less than 100...? not sure but you should be able to get something to work..

if($page->bfd_year < 100) $page->bfd_year = '00' . $page->bfd_year;
// test
// echo $page->bfd_year;

$year = date(Y, strtotime($page->bfd_year));
 
Link to comment
Share on other sites

That helped. Thanks! It still needs some polishing to get 'Monday 7th of December 0043bc' show up as 43bc but I'll figure that out.

In case anybody's interested, calculating people's age in bc times results in negative numbers, my solution is:

$atagetxt = str_replace('-', '', ' at the age of ' . ($eventyear - $birthyear));
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...