Last post Apr 14, 2012 09:13 AM by ruipedromachado
Apr 14, 2012 08:21 AM|info2ambrish|LINK
My DAteTime Is following:
8/13/2009 12:00:00 AM
I am using Following:
DateTime date = DateTime.ParseExact("8/13/2009 12:00:00 AM", "yyyy-MM-dd", CultureInfo.CurrentCulture).Date;
but its giving following exception:
String was not recognized as a valid DateTime
How to convert this dateTime Format that value updated into oracle table.
Pls Solve my issue.
Thanks in advance
Apr 14, 2012 08:51 AM|sanjayverma_mca|LINK
This is may be because the server datetime format is different from the format you are sending to the server.
So you need to convert the datetime to that format.It may be like this
DateStr = lblMatchDate.Text;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB");
DateTime dt = Convert.ToDateTime(DateStr);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
dt = Convert.ToDateTime(dt);
Apr 14, 2012 09:13 AM|ruipedromachado|LINK
oracle has to functions that are amaizing to work with dates. to_char and to_date.
in your case :
lets say you have your
inside a datetime variable called DTtoOracle
so on your SQL statement just use to_date function. this function accepts 2 arguments. first is the given date and second is the format.
to_date('" + DTtoOracle.Date.ToString("yyyy-MM-dd") + "','yyyy-mm-dd')
so what we are doing is specify the format on the first argument from your datetime variable and on the second argument you are telling oracle whats the format you are sending to the database.
full example :
SELECT * FROM MYTABLE WHERE DATEFIELD = to_date('" + DTtoOracle.Date.ToString("yyyy-MM-dd") + "','yyyy-mm-dd');
this should return all records where your date field = same date as your variable.