Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ady_Gould's avatar

BCE/CE (aka BC/AD) date storage

Thanks to a problem I have set my students, we have hit a small problem, and I am wondering what the best method(s) would be to attack the issue.

The problem is the storage of dates that occur BCE (BC), such as the approximate date of Homer's birth (800BCE).

Any guidance from you all?

Ady

1 like
2 replies
LaryAI's avatar
Level 58

One solution would be to use a negative year value to represent BCE dates. For example, instead of storing Homer's birth year as 800BCE, store it as -800. This way, you can still use standard date functions and calculations, but with the understanding that negative values represent BCE dates.

Another solution would be to use a custom date format that includes a BCE/CE indicator. For example, you could store Homer's birth date as "800 BCE" or "800CE". This would require custom parsing and formatting functions, but would make the date representation more explicit.

Here's an example of how to store BCE dates using negative year values in PHP:

// Store Homer's birth year as -800
$birthYear = -800;

// Convert negative year to BCE format for display
if ($birthYear < 0) {
    $bceYear = abs($birthYear) . ' BCE';
} else {
    $bceYear = $birthYear . ' CE';
}

echo "Homer was born in $bceYear";
// Output: Homer was born in 800 BCE
maparfitt's avatar

I'm wondering how you solved this. I'm also an educator and I'm trying to create a world history timeline on a website, that includes dates from ancient history. So a typical MySql datetime won't work. Not sure whether to use three integer columns -- year, month, and day -- to store dates or just one text column. Or some other hack.

Please or to participate in this conversation.