Click here to Skip to main content
12,945,401 members (85,476 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 26 Aug 2010

Converting dates to the Roman equivalent

, 26 Aug 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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"))
                // 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!");


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

You may also be interested in...

Comments and Discussions

Bug[CRITICAL ERROR] Database no longer exists. Pin
Brisingr Aerowing24-Mar-15 13:34
professionalBrisingr Aerowing24-Mar-15 13:34 
Generalit was nice. helpful Pin
Hiren Solanki29-Aug-10 20:02
memberHiren Solanki29-Aug-10 20:02 
QuestionCoding Horror? Pin
bhiller31-Aug-10 2:13
memberbhiller31-Aug-10 2:13 
AnswerRe: Coding Horror? Pin
OriginalGriff31-Aug-10 2:26
memberOriginalGriff31-Aug-10 2:26 
AnswerRe: Coding Horror? Pin
OriginalGriff31-Aug-10 2:26
memberOriginalGriff31-Aug-10 2:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170518.1 | Last Updated 26 Aug 2010
Article Copyright 2010 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid