Click here to Skip to main content
15,923,168 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Please help me,

I want to change date value into words for example:-
convert this "22/08/2002" into this "Twenty Second August Two thousand two"

give me solution or some idea please.

What I have tried:

I tried this

lbldobinwords.Text = String.Format("{0:dd MMMM yyyy}", dtpdob.Value);

but this gives me output like this "22 August 2002".
Posted
Updated 23-Apr-16 23:57pm

Check this
C#
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] day = {"First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth",
                            "Eleventh","Tweleveth","Thirteenth","Fourteenth","Fifteenth","Sixteeth","Seventeenth","Eighteenth","Ninteenth","twentyth",
                            "Twenty First","Twenty Second","Twenty Third","Twenty Fourth","Twenty Fifth","Twenty Sixth","Twenty Seventh","Twenty Eighth","Twenty Ninth","thirtieth","Thirty First"};
            DateTime dateValue = DateTime.Now;
            string month = String.Format("{0:MMMM}", dateValue);
            string year = ConvertNumbertoWords(dateValue.Year);
            string inWords = string.Format("{0} {1} {2}", day[dateValue.Day - 1], month, year);

        }

        public static string ConvertNumbertoWords(int number)
        {
            if (number == 0)
                return "Zero";
            if (number < 0)
                return "minus " + ConvertNumbertoWords(Math.Abs(number));
            string words = "";
           
            if ((number / 1000) > 0)
            {
                words += ConvertNumbertoWords(number / 1000) + " Thousand ";
                number %= 1000;
            }
            if ((number / 100) > 0)
            {
                words += ConvertNumbertoWords(number / 100) + " Hundred ";
                number %= 100;
            }
            if (number > 0)
            {
                if (words != "")
                    words += "and ";
                var unitsMap = new[] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Tweleve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen" };
                var tensMap = new[] { "Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };

                if (number < 20)
                    words += unitsMap[number];
                else
                {
                    words += tensMap[number / 10];
                    if ((number % 10) > 0)
                        words += " " + unitsMap[number % 10];
                }
            }
            return words;
        }
    }
}


Number Conversion used from Numbers to Words[^]
 
Share this answer
 
Comments
varuncodee 24-Apr-16 8:41am    
Thanks Karthik code worked like a charm. my problem is solved, now i am trying to understand the code ... Thanks
Karthik_Mahalingam 24-Apr-16 8:42am    
cool varun :)
you really need to get the numeric components of the date, eg

22
08
2002

and run them through something like this NumberText/NumberText.cs at master · robertgreiner/NumberText · GitHub[^] or this C# - Convert Numbers to Text (Words)[^]

where you extend that code to handle 08 -> August

do a google for 'c# convert number text' and you'll see plenty of other ways of doing it - you dont even need a large range of numbers if you're only doing days, months, years

[edit]
Humanizer GitHub - Humanizr/Humanizer: Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities[^] also has a lot of goodies .ToWords() for example - you could use that as a base and extend it [/edit]
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900