Friday, August 6, 2010

DateTime object convertion

Hi,

While I was working on Sharepoint requirements, I have faced a scenario of rading the DateTime column, where my problem was I require only date but the DateTime object reference which I have got after reading from the list's column value holds both Date as well as Time.

So I came across the below procedure to resolve my problem.

**************************************

DateTime.Parse(item[dateFieldName].ToString()).ToString("MM/dd/yyyy");

**************************************


other way of doing the same is as below:
 
***************************************
string dateString = "Mon 16 Jun 8:30 AM 2008";

string format = "ddd dd MMM h:mm tt yyyy"; DateTime dateTime = DateTime.ParseExact(dateString, format,
CultureInfo.InvariantCulture);
Console.WriteLine(dateTime);

**************************************
 
This has resoved my problem.
 

No comments:

Post a Comment