mysql - c# string date format from d.M.yyyy to yyyy-MM-dd -
please, how can convert date string csv import grid , mysql database?
i import date in dd.mm.yyyy format , must format yyyy-mm-dd mysql database.
my code datagrid rows
datagridview1.rows.add(counter, "1", linein[0], controlprice, linein[3]);
linein[0] date string... thank you
its best use datetime.parseexact
based on example, need cast string before passing function.
you should consider happens if invalid date in csv, how want handle that? or expect date , want halt processing?
here's linqpad example used test:
object date = "12.2.2014"; var result = datetime.parseexact(date.tostring(), "d.m.yyyy", null).tostring("yyyy-mm-dd"); console.writeline(result);
see post more info:
datetime conversion , parsing datetime.now.tostring(“mm/dd/yyyy hh:mm:ss.fff”)
Comments
Post a Comment