sql - PLSQL - Round Date to the nearest century? -


here output trying get:

number of slashes: 2 in 25 days is: 19-feb-15 raw number is: 1.666666667e-01 rounded number is: .17 nearest century: 01-jan-01 

i'm not sure how round "ddate25" nearest century?

here code have far:

set serveroutput on  declare vfilepath varchar2 (100) := 'c\temp\procdb.mdf'; vfilepath1 varchar2 (100); nnumber16 float; ddate25 date := sysdate+25; begin vfilepath1 := replace (vfilepath, '\'); dbms_output.put_line('number of slashes:' || (length(vfilepath)-length(vfilepath1))); dbms_output.put_line('in 25 days is:' || to_char(ddate25, 'mm-dd-yyyy')); nnumber16 := 1/6; dbms_output.put_line('the raw number is: ' || to_char(nnumber16, '9.999999999eeee')); dbms_output.put_line('the rounded number is: ' || round(nnumber16, 2));  end; 

thanks,

you can use the trunc(date) function if want 'round down' current century (so date in 2051 gives 2001); or the round(date) function if want round (so 2051 gives 2101). either way, cc format mask first day of century:

sql> select round(sysdate + 25, 'cc') dual;  trunc(sysdate+25,'c ------------------- 2001-01-01 00:00:00 

so can use:

round(ddate25) 

and can format need; without nls assumptions:

dbms_output.put_line('nearest century: '   || to_char(round(ddate25, 'cc'), 'dd-mon-rr', 'nls_date_language=english')); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -