日期处理

1、日期比较:
在今天之前:
select * from up_date where update < to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from tablename where update <= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

在今天只后:
select * from tablename where update > sysdate    ---    与当前系统时间比较
select * from tablename where update >= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

精确时间:
select * from tablename where update = to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

在某段时间内:
select * from tablename where update between to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss'and to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from tablename where update < to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss'and update > to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from tablename where update <= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss'and update >= to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
2、获取系统日期:

    select sysdate from dual;

    3、日期格式化:

    格式化日期: TO_CHAR(SYSDATE(),'YY/MM/DD HH24:MI:SS) 或 TO_DATE(SYSDATE(),'YY/MM/DD HH24:MI:SS)
    格式化数字: TO_NUMBER

   注:TO_CHAR  把日期或数字转换为字符串 TO_CHAR(number, '格式') 、TO_CHAR(salary, '$99,999.99') 、TO_CHAR(date, '格式')

           TO_DATE  把字符串转换为数据库中的日期类型TO_DATE(char, '格式')

           TO_NUMBER  将字符串转换为数字 TO_NUMBER(char, '格式')

   4、日期处理

    SimpleDateFormat sdf = new SimpleDateFoemat("yyyy/MM/dd HH:mm:ss");

    String str = sdf.format(new Date());

    from tablename where date <= to_cahr(str,'yyyy/MM/dd HH24:MI:SS')

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值