简体   繁体   中英

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 just 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;

Oracle trunc()函数删除了时间部分:

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM