Oracle date formatting
in my c# programme i am requesting data from an oracle database and one field is the date abd time in this format - 12/09/2008 15:11:17
, is there anyway i can jus开发者_StackOverflow社区t return the date?
Is there also a way of ensuring its in british format, by modifying the sql to be dd/mm/yyyy
thanks
You could get the date part of the DateTime
using C#, You could do
string date = MyDateTime.ToString("dd/MM/yyyy");///let MyDateTime be your DateTime variable
If you want to do in Oracle, you can use to_char
for example,
select to_char(sysdate, 'dd/MM/yyyy') From dual;
The Oracle trunc() function removes the time part:
select trunc(datecol) from mytable;
In your sql query to oracle you can
to_date('12/09/2008 15:11:17', 'dd/MM/yyyy')
where you replace the date with your field in the oracle db.
Alternatively, you can handle it on the C# side with formatting
CultureInfo ukCulture = new CultureInfo("en-GB");
//this assuming you do not have a datetime type
DateTime myDateTime = DateTime.Parse("12/09/2008 15:11:17", ukCulture.DateTimeFormat);
string result = myDateTime.ToString(ukCulture.DateTimeFormat.ShortDatePattern));
精彩评论