I need to get the short month name for the full month name.
For example,
DateTime.Now.ToString("MMMM", CultureInfo.CurrentCulture);
this returns - "agosto"
DateTime.Now.ToString("MMM", CultureInfo.CurrentCulture);
this returns - "ago."
This two codes works only to get the current month. I need to get the short month name for all the months.
If I give "agosto", it should return "ago.". How could I achieve this?
An alternative to Soner's answer that doesn't use a loop:
public static string GetAbbreviatedFromFullName(string fullname)
{
DateTime month;
return DateTime.TryParseExact(
fullname,
"MMMM",
CultureInfo.CurrentCulture,
DateTimeStyles.None,
out month)
? month.ToString("MMM")
: null;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With