rajesh_khater
asked on
Converting a string from one date format to another
I have a string which contains date in yyyymmdd format, eg: 20050415.
I need to convert it to a string in dd-MMM-yyyy format eg: 15-Apr-2007.
What is the best way to do this?
I need to convert it to a string in dd-MMM-yyyy format eg: 15-Apr-2007.
What is the best way to do this?
use String.Format
try this. just make sure that datefield is of type date
String.Format("{0:dd-MMM-y yyy}", datefield)
String.Format("{0:dd-MMM-y
ASKER
it is not of type date, as I already told.
string mystr="20050415";
DateTime dt = DateTime.Parse (long.Parse (mystr).ToString());
string mynewstring=String.Format( "{0:dd-MMM -yyyy}", dt)
DateTime dt = DateTime.Parse (long.Parse (mystr).ToString());
string mynewstring=String.Format(
ASKER
long.parse will take it as long value 20050415, which is not correct. DateTime.Parse interprets long value as a certain offset from a base date, i think.
ASKER
long.Parse(mystr).ToString () is equal to mystr only ! That will not help at all.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
my solution works, I tested it