DateFormat 03/05 to MAR05, how?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DateTime type data for my grid column. I want to display it in the
cells as

MONYR, as MAR05 JAN05 etc. Cannot find it in DateTime format, is there any
quick way to do it (instead of convert my column type from DateTime to string
and then parse it by myself)?

Thanks a lot

Chris
 
DateTime.ToString("MMMYY") ?

(You may need to do a ToUpper if you want the month in capital letters).
 
chrisben said:
I have a DateTime type data for my grid column. I want to display it in the
cells as

MONYR, as MAR05 JAN05 etc. Cannot find it in DateTime format, is there any
quick way to do it (instead of convert my column type from DateTime to string
and then parse it by myself)?

You mean something like:

using System;

public class Foo
{
public static void Main()
{
DateTime dt = DateTime.Now;
Console.WriteLine(dt.ToString("MMMyy").ToUpper());
}
}

The month name used is Culture specific so is capable of being
localized.

/J\
 
Thanks a lot Adam. It works. Hard to toupper since I define the column type
as datatime and the format is predefined. however, i can live with it.
Thanks again for quick response

Chris
 
Thanks Jonathan. Sorry for my ignorance. Would you please explain what
"Culture specific" means?
 
chrisben said:
Thanks Jonathan. Sorry for my ignorance. Would you please explain what
"Culture specific" means?

'Culture' is a .NETism for what is commonly called 'locale' in other
places, essentially it is a set of rules for how things like dates,
time, currency and so forth are represented in different locatlities.
See for instance the output of this slightly altered version of the above:

using System;

public class Foo
{
public static void Main()
{
DateTime dt = DateTime.Now;
IFormatProvider format = new System.Globalization.CultureInfo("en-GB", true);
Console.WriteLine(dt.ToString("MMMyy",format).ToUpper());
format = new System.Globalization.CultureInfo("de-DE", true);
Console.WriteLine(dt.ToString("MMMyy",format).ToUpper());
format = new System.Globalization.CultureInfo("ru-RU", true);
Console.WriteLine(dt.ToString("MMMyy",format).ToUpper());

}
}


The second argument to ToString() indicates the 'locale' that is to be
used in formatting the date.

/J\
 
thanks

Jonathan Stowe said:
'Culture' is a .NETism for what is commonly called 'locale' in other
places, essentially it is a set of rules for how things like dates,
time, currency and so forth are represented in different locatlities.
See for instance the output of this slightly altered version of the above:

using System;

public class Foo
{
public static void Main()
{
DateTime dt = DateTime.Now;
IFormatProvider format = new System.Globalization.CultureInfo("en-GB", true);
Console.WriteLine(dt.ToString("MMMyy",format).ToUpper());
format = new System.Globalization.CultureInfo("de-DE", true);
Console.WriteLine(dt.ToString("MMMyy",format).ToUpper());
format = new System.Globalization.CultureInfo("ru-RU", true);
Console.WriteLine(dt.ToString("MMMyy",format).ToUpper());

}
}


The second argument to ToString() indicates the 'locale' that is to be
used in formatting the date.

/J\
 
Jonathan,

However this what you wrote is in my opinion not true
The month name used is Culture specific so is capable of being
localized.

MMM is forever the short name month abbreviation, from the language that is
used, in the OS and is not depending from the culture. While dd is always
the day in two figures.

Cor
 
Back
Top