Convert date to letter in spanish

hello, I need to convert this format date 12/04/1996 to letter format i.e.
april twelve, nineteen hundred and ninety six in spanish

1 Like

A simple pseudo code to convert the date format in Spanish:

// Get the input date.
string inputDate = "12/04/1996";

// Split the input date into day, month, and year.
string[] dateParts = inputDate.Split("/");

// Get the day, month, and year as integers.
int day = Convert.ToInt32(dateParts[0]);
int month = Convert.ToInt32(dateParts[1]);
int year = Convert.ToInt32(dateParts[2]);

// Convert the month to Spanish.
string monthName = "";
switch (month)
{
    case 1:
        monthName = "enero";
        break;
    case 2:
        monthName = "febrero";
        break;
    case 3:
        monthName = "marzo";
        break;
    case 4:
        monthName = "abril";
        break;
    case 5:
        monthName = "mayo";
        break;
    case 6:
        monthName = "junio";
        break;
    case 7:
        monthName = "julio";
        break;
    case 8:
        monthName = "agosto";
        break;
    case 9:
        monthName = "septiembre";
        break;
    case 10:
        monthName = "octubre";
        break;
    case 11:
        monthName = "noviembre";
        break;
    case 12:
        monthName = "diciembre";
        break;
}

// Convert the year to Spanish.
string yearName = "";
if (year < 2000)
{
    yearName = "mil novecientos " + year.ToString();
}
else
{
    yearName = year.ToString();
}

// Construct the output date in Spanish.
string outputDate = monthName + " " + day + ", " + yearName;

// Output the result.
Console.WriteLine(outputDate);

This workflow will output the following:

abril doce, mil novecientos noventa y seis

Hope this helps

Cheers @Eduardo_Piracoca

@Eduardo_Piracoca

Try this Linq

outputDate = DateTime.ParseExact(inputDate, "dd/MM/yyyy", CultureInfo.InvariantCulture)
    .ToString("MMMM dd, yyyy", new CultureInfo("es-ES"));

Hi,

You can use below expression

dateVariable = DateTime.ParseExact(β€œ12/04/1996”, β€œMM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture)
formattedDate = dateVariable.ToString(β€œD”, New System.Globalization.CultureInfo(β€œes-ES”))

This will give you the output β€œ12 de abril de 1996” in letter format in Spanish.

Hi,

Can you check the following post?

Regards,