Converting dates to the Roman equivalent






4.67/5 (3 votes)
If your tutor asks you to convert years to the Roman equivalent, (e.g. 2010 to MMX) then you are not alone! Here is the simplest, most foolproof way to do it!
Tutors can be so unimaginative! Frequently they ask students to convert years to the Roman equivalent, and so dutifully you go off and re-invent the wheel. AGAIN.
Now, you won't have to! Just download a small ZIP file, decompress it to your My Documents folder, and add a small piece of code - easy! You might want to change the comments a bit, a few of the names perhaps to make it look like you wrote it, but Hey! That's easier than actually working out how to do it, isn't it?
Procedure: Download the conversion database here[^] and unzip it to your My Documents folder. Note that this conversion works from the founding of Rome (start of Ab Urbe Condita as you would expect) to the end of the Gregorian calender in 4246
To make it easier, this is an SQLCE database, which means it is small, compact and does not require SQL Server or MySQL to be installed - it works with the .NET SqlServerCe assembly which is installed with .NET automatically. Additionally, it means this will work with Windows CE or Windows Mobile!
Add a reference in your project to the "System.Data.SqlServerCe" assembly, and a "
using System.Data.SqlServerCe;
" to the top of your source file.
Then just paste the following code into your app and use the GetRomanDate method.
/// <summary>
/// Get the Roman eqivilant of a year (normal Gregorian calender)
/// </summary>
/// <param name="year">Year to convert</param>
/// <returns>Roman numeral version of the year</returns>
private string GetRomanDate(int year)
{
return GetRomanDate(year, false); // Convert without Ab Urbe Condita
}
/// <summary>
/// Get the Roman eqivilant of a year
/// Normal Gregorian calender, or Ab Urbe Condita
/// </summary>
/// <param name="year">Year to convert</param>
/// <param name="abUrbeCondita">True if Ab Urbe Condita convertion is required</param>
/// <returns></returns>
private string GetRomanDate(int year, bool abUrbeCondita)
{
// Connect to the DB
using (SqlCeConnection con = new SqlCeConnection(@"Data Source=" + Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\RomanDates.sdf;Persist Security Info=True"))
{
con.Open();
// Fetch the roman numeral string
string sql = "SELECT * FROM Years WHERE Year=@YEAR";
using (SqlCeCommand cmd = new SqlCeCommand(sql, con))
{
cmd.Parameters.AddWithValue("@YEAR", year);
using (SqlCeDataReader dr = cmd.ExecuteReader())
{
// And return the word version.
return (dr.Read() ? (string) dr[(abUrbeCondita ? "AbUrbeCondita" : "Roman")] : "Outside the bounds of time!");
}
}
}
}