Oracle 日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6071041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle date formatting
提问by rik
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?
在我的 C# 程序中,我从 oracle 数据库请求数据,一个字段是这种格式的日期和时间 -12/09/2008 15:11:17
无论如何我可以只返回日期吗?
Is there also a way of ensuring its in british format, by modifying the sql to be dd/mm/yyyy
是否还有一种方法可以通过将 sql 修改为 dd/mm/yyyy 来确保其采用英国格式
thanks
谢谢
回答by FIre Panda
You could get the date part of the DateTime
using C#, You could do
您可以获得DateTime
使用 C#的日期部分,您可以这样做
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,
如果你想在 Oracle 中做,你可以使用to_char
例如,
select to_char(sysdate, 'dd/MM/yyyy') From dual;
回答by Tony Andrews
The Oracle trunc() function removes the time part:
Oracle trunc() 函数去掉了时间部分:
select trunc(datecol) from mytable;
回答by Kamal
In your sql query to oracle you can
在您对 oracle 的 sql 查询中,您可以
to_date('12/09/2008 15:11:17', 'dd/MM/yyyy')
where you replace the date with your field in the oracle db.
您在 oracle 数据库中用您的字段替换日期。
Alternatively, you can handle it on the C# side with formatting
或者,您可以使用格式化在 C# 端处理它
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));