且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

比较Oracle Date与C#DateTime

更新时间:2023-01-29 17:22:19

您可以使用Oracle TO_DATE 功能.

You can use the Oracle TO_DATE function.

WHERE someDateColumn <= TO_DATE(c#_date, 'YYYY/MM/DD')

有关c#日期(请参见自定义日期和时间字符串):

For the c# date (see custom date and time strings):

DateTime.Now.ToString("yyyy/MM/dd")

如果要增加小时/分钟/秒,则可以进行相应的修改.

If you want to add hours/minutes/seconds, you can modify accordingly.

edit-实际上,因为您提到了整个事情,而不仅仅是日期,所以我将其添加. :)

edit - Actually since you mentioned the whole thing and not just the date, I'll add it. :)

WHERE someDateColumn <= TO_DATE(c#_date, 'YYYY/MM/DD HH24:MI:SS')
DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")

在家里,我无法运行它,但这应该可以工作.

At home so I can't run it, but that should work.

要使用where子句构建字符串,请执行以下操作:

To build a string with the where clause, you'd do this:

string someQuery = "SELECT * FROM aTable WHERE someDateColumn <=  TO_DATE('" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "', 'YYYY/MM/DD')"

如果要使用特定日期而不是DateTime.现在,只需将保存该日期的变量放在那里.

If you wanted to use a specific date rather then DateTime.Now, just put the variable holding it there instead.