2013-02-08
Javascript ] javascript 날짜(Date) 관련 함수.
// 현재 일자보다 7일전 날짜 구하기.
var dt = new Date();
var fd = timeShift(dt, "-7");
var val = fd.getFullYear()+"-"+(fd.getMonth()+1)+"-"+fd.getDate();
// fd 값을 가진 날의 요일
fnSetFromDateVal(fd);
// fd ~ dt 의 기간.
betweenDay(fd, dt);
/**
* a : date()
* s : 이동하고자 하는 일자 기간.(7 - 7일, 15 - 15일)
*/
function timeShift(a,str){
b = new Date();
b.setTime(a.getTime() + ((str) * 24 * 60 * 60 * 1000));
return b;
}
/**
* 특정날짜의 요일을 구한다.
* time : 날자형식의 데이터.
*/
function getDayOfWeek(time) {
var now = new Date(time);
var day = now.getDay(); //일요일=0,월요일=1,...,토요일=6
// var week = new Array('일','월','화','수','목','금','토');
// return week[day]; // 리턴값은 일 ~ 토 로 표시된다.
return day; // 리턴값은 0 ~ 6 로 표시된다.
}
/**
* 입력받을 날자 사이의 기간을 리턴
* fd : 시작일자, td : 종료일자.
*/
function betweenDay(fd, td) {
var betweenDay = (fd.getTime() - td.getTime())/1000/60/60/24;
return betweenDay;
}
라벨:
날짜,
자바스크립트,
date,
javascript
2012-09-16
DBMS/오라클]오라클에서 해당월 날짜 구하기 / 오늘날짜 해당주 날짜 구하기
원본 출처 사이트 : http://daenamoo09.egloos.com/1182925 입니다.
아래의 내용은 제가 보기 편하기 위해 가져다 놓은 것입니다.
# 해당 일부터 30일 날짜
SELECT TO_CHAR(TO_DATE(BB.DAY, 'YYYYMMDD') + NUM, 'YYYY-MM-DD') AS DAY
FROM (
SELECT ROWNUM AS NUM
FROM DICTIONARY A,(
SELECT B.DAY AS BDAY, C.DAY AS CDAY
FROM
( SELECT TO_CHAR(SYSDATE,'YYYYMM') || '01' AS DAY FROM DUAL ) B,
( SELECT TO_CHAR(LAST_DAY(SYSDATE),'YYYYMMDD') AS DAY FROM DUAL ) C
) B
WHERE ROWNUM <= TO_DATE(B.CDAY, 'YYYYMMDD') - TO_DATE(B.BDAY, 'YYYYMMDD') + 1) AA,
( SELECT TO_CHAR(SYSDATE - TO_NUMBER(TO_CHAR(SYSDATE,'D')) + 1,'YYYYMMDD') AS DAY FROM DUAL ) BB
FROM (
SELECT ROWNUM AS NUM
FROM DICTIONARY A,(
SELECT B.DAY AS BDAY, C.DAY AS CDAY
FROM
( SELECT TO_CHAR(SYSDATE,'YYYYMM') || '01' AS DAY FROM DUAL ) B,
( SELECT TO_CHAR(LAST_DAY(SYSDATE),'YYYYMMDD') AS DAY FROM DUAL ) C
) B
WHERE ROWNUM <= TO_DATE(B.CDAY, 'YYYYMMDD') - TO_DATE(B.BDAY, 'YYYYMMDD') + 1) AA,
( SELECT TO_CHAR(SYSDATE - TO_NUMBER(TO_CHAR(SYSDATE,'D')) + 1,'YYYYMMDD') AS DAY FROM DUAL ) BB
# 현재 날짜에서 일주일 날짜..
SELECT TO_CHAR(TO_DATE(BB.DAY, 'YYYYMMDD') + NUM-1, 'YYYY-MM-DD') AS DAY
FROM (
SELECT ROWNUM AS NUM
FROM DICTIONARY A,(
SELECT B.DAY AS BDAY, C.DAY AS CDAY
FROM
( SELECT TO_CHAR(SYSDATE - TO_NUMBER(TO_CHAR(SYSDATE,'D')) + 1,'YYYYMMDD') AS DAY FROM DUAL ) B,
( SELECT TO_CHAR(SYSDATE - TO_NUMBER(TO_CHAR(SYSDATE,'D')) + 7,'YYYYMMDD') AS DAY FROM DUAL ) C
) B
WHERE ROWNUM <= TO_DATE(B.CDAY, 'YYYYMMDD') - TO_DATE(B.BDAY, 'YYYYMMDD') + 1) AA,
( SELECT TO_CHAR(SYSDATE - TO_NUMBER(TO_CHAR(SYSDATE,'D')) + 1,'YYYYMMDD') AS DAY FROM DUAL ) BB
FROM (
SELECT ROWNUM AS NUM
FROM DICTIONARY A,(
SELECT B.DAY AS BDAY, C.DAY AS CDAY
FROM
( SELECT TO_CHAR(SYSDATE - TO_NUMBER(TO_CHAR(SYSDATE,'D')) + 1,'YYYYMMDD') AS DAY FROM DUAL ) B,
( SELECT TO_CHAR(SYSDATE - TO_NUMBER(TO_CHAR(SYSDATE,'D')) + 7,'YYYYMMDD') AS DAY FROM DUAL ) C
) B
WHERE ROWNUM <= TO_DATE(B.CDAY, 'YYYYMMDD') - TO_DATE(B.BDAY, 'YYYYMMDD') + 1) AA,
( SELECT TO_CHAR(SYSDATE - TO_NUMBER(TO_CHAR(SYSDATE,'D')) + 1,'YYYYMMDD') AS DAY FROM DUAL ) BB
# 시작일부터 끝일까지
SELECT TO_CHAR(TO_DATE('[SDATE]', 'YYYY-MM-DD') + NUM-1, 'YYYY-MM-DD') AS DAY
FROM (
SELECT ROWNUM NUM
FROM DICTIONARY
WHERE ROWNUM <= TO_DATE('[EDATE]', 'YYYY-MM-DD') - TO_DATE('[SDATE]', 'YYYY-MM-DD') + 1
)
FROM (
SELECT ROWNUM NUM
FROM DICTIONARY
WHERE ROWNUM <= TO_DATE('[EDATE]', 'YYYY-MM-DD') - TO_DATE('[SDATE]', 'YYYY-MM-DD') + 1
)
# 날짜계산
/* 어제 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE-1) AND TRUNC(SYSDATE-1)
+0.99999421
/* 오늘 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) + 0.99999421
/* 내일 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE+1) AND TRUNC(SYSDATE+1)
+0.99999421
/* 금주 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE+1)-TO_CHAR(SYSDATE,'D')
AND TRUNC(SYSDATE+1)-TO_CHAR(SYSDATE,'D')
+6.99999421
/* 차주 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE+8)-TO_CHAR(SYSDATE, 'D')
AND TRUNC(TRUNC(SYSDATE)+14.99999421)-TO_CHAR
(SYSDATE, 'D')
/* 금월 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE+1)-TO_CHAR(SYSDATE,'DD')
AND TRUNC(LAST_DAY(SYSDATE))+0.99999421
/* 전월 */ 날짜칼럼 BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-1)+1)-TO_CHAR
(SYSDATE,'DD')
AND TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE, -1)))
+0.99999421
/* 차월 */ 날짜칼럼 BETWEEN ADD_MONTHS(TRUNC(SYSDATE),1)-TO_CHAR
(SYSDATE,'DD')+1
AND LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE),1)
+0.99999421)
/* 어제 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE-1) AND TRUNC(SYSDATE-1)
+0.99999421
/* 오늘 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE) + 0.99999421
/* 내일 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE+1) AND TRUNC(SYSDATE+1)
+0.99999421
/* 금주 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE+1)-TO_CHAR(SYSDATE,'D')
AND TRUNC(SYSDATE+1)-TO_CHAR(SYSDATE,'D')
+6.99999421
/* 차주 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE+8)-TO_CHAR(SYSDATE, 'D')
AND TRUNC(TRUNC(SYSDATE)+14.99999421)-TO_CHAR
(SYSDATE, 'D')
/* 금월 */ 날짜칼럼 BETWEEN TRUNC(SYSDATE+1)-TO_CHAR(SYSDATE,'DD')
AND TRUNC(LAST_DAY(SYSDATE))+0.99999421
/* 전월 */ 날짜칼럼 BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-1)+1)-TO_CHAR
(SYSDATE,'DD')
AND TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE, -1)))
+0.99999421
/* 차월 */ 날짜칼럼 BETWEEN ADD_MONTHS(TRUNC(SYSDATE),1)-TO_CHAR
(SYSDATE,'DD')+1
AND LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE),1)
+0.99999421)
# 특정일 까지의 간격을 년, 개월, 일로 표현하기
SELECT
TRUNC(MONTHS_BETWEEN(SYSDATE, TO_DATE('19970101', 'YYYYMMDD'))/12) "년",
TRUNC(MONTHS_BETWEEN(SYSDATE, TO_DATE('19970101', 'YYYYMMDD')) -
TRUNC(MONTHS_BETWEEN(SYSDATE, TO_DATE('19970101', 'YYYYMMDD'))/12) *
12) "개월",
TRUNC((MONTHS_BETWEEN(SYSDATE,TO_DATE('19970101', 'YYYYMMDD')) -
TRUNC(MONTHS_BETWEEN(SYSDATE, TO_DATE('19970101', 'YYYYMMDD')))) *
30.5) "일"
피드 구독하기:
글 (Atom)