Wednesday, June 6, 2012

Convert String to DateTime with Format

use function: DateTimeFormatInfo

example:
string strDate = "18-12-1992";
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
dtfi.ShortDatePattern = "dd/MM/yyyy";
dtfi.DateSeparator = "/";
DateTime objDate = Convert.ToDateTime(strDate, dtfi);

It's really useful for manipulating DateTimePicker value.

No comments:

Post a Comment