prabhu p

prabhu p

  • 2k
  • 181
  • 98.1k

Error on date conversion

Mar 28 2018 1:15 AM

I converting date format from MM/dd/yyyy to dd/MM/yyyy

for example

from date 03/01/2018( MM/dd/yyyy ) textbox format
To date 03/27/2018( MM/dd/yyyy ) textbox format 
 
I want to convert to   dd/MM/yyyy for DB

DateTime dt = DateTime.ParseExact(from, "dd/MM/yyyy", CultureInfo.InvariantCulture);

No error for from date 

DateTime dt1 = DateTime.ParseExact(To, "dd/MM/yyyy", CultureInfo.InvariantCulture);

error on above line dt1 String is not valid datetime
what happening in todate after converting to  dd/MM/yyyy it will be 27/03/2018 and system taking 27 as month and showing error .
 
Please help on this
 
Thanks in advance

Answers (3)