[英]parsing year from DATE in Oracle SQL
a simple question I'm sure... but i am just drawing a blank on how to get just the ear from a stored DATE in a table. 我敢肯定,这是一个简单的问题...但是我只是在如何从表中存储的DATE的耳朵上画一个空白。 what i am truing to do is generate a query that returns a title, id and the year a course was offered.... and i know i haven't added any thing in the where clause.. here is what i have so far:
我正在努力做的是生成一个查询,该查询返回标题,ID和所提供课程的年份....我知道我没有在where子句中添加任何东西..这是到目前为止我所拥有的:
select title, id, To_Char(c.START_DATE,'YYYY') AS year
from (select c.COURSE_TITLE as title, g.STUDENT_ID as id, c.START_DATE
from COURSES c, COURSE_INFO g) m;
i have a start date stored, but i only want the year component 我存储了开始日期,但是我只想要年份部分
I use the format() method for Date objects to pull apart dates. 我对Date对象使用format()方法来拆分日期。 Using Dirk's datetext, here is how I would go about breaking up a date into its constituent parts:
使用Dirk的日期文本,这是将日期分成其组成部分的方法:
datetxt <- c("2010-01-02", "2010-02-03", "2010-09-10") datetxt <- as.Date(datetxt) df <- data.frame(date = datetxt, year = as.numeric(format(datetxt, format = "%Y")), month = as.numeric(format(datetxt, format = "%m")), day = as.numeric(format(datetxt, format = "%d")))
Which gives: 这使:
> df date year month day 1 2010-01-02 2010 1 2 2 2010-02-03 2010 2 3 3 2010-09-10 2010 9 10
There is a Year function in oracle oracle中有Year函数
select title, id, Year(START_DATE) AS year
from (select c.COURSE_TITLE as title, g.STUDENT_ID as id, c.START_DATE
from COURSES c, COURSE_INFO g) m;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.