delphi format conversion

TO_CHAR is to convert a number to a string or date

TO_DATE string is converted into a database to obtain a date type conversion functions
TO_NUMBER characters into digital

TO_CHAR TO_CHAR function used for processing a digital
TO_CHAR (number, 'format')
TO_CHAR (the salary, '$ 99,999.99');
use TO_CHAR function processing date
TO_CHAR (date, 'format');

² TO_NUMBER
using TO_NUMBER function to convert a character into a digital
TO_NUMBER (char [, 'format'])

Use TO_DATE TO_DATE function to convert the characters to date
TO_DATE (char [, 'format'])

Digital Formats
9 represents a number
0 0 forced display
$ a $ character placed
L placing a floating local currency symbol
. Decimal point
, thousands digit indicator

 date format
format control described
YYYY, YYY, YY represent four digital in three, two of
YEAR-year spell
MM month figures
spelling MONTH month
acronym MON month
DD digital day
DAY week's spelling
DY week Abbreviation
AM represents a morning or afternoon
HH24, HH12 12-hour or 24-hour
MI minutes
SS seconds
SP digital spelling
TH ordinal numbers

"Special character" if special characters
HH24: MI: SS AM 15:43:20 PM

日期例子:
SELECT TO_DATE('2006-05-01 19:25:34', 'YYYY-MM-DD HH24:MI:SS') FROM DUAL
SELECT TO_DATE('2006-05-01 19:25', 'YYYY-MM-DD HH24:MI') FROM DUAL
SELECT TO_DATE('2006-05-01 19', 'YYYY-MM-DD HH24') FROM DUAL
SELECT TO_DATE('2006-05-01', 'YYYY-MM-DD') FROM DUAL
SELECT TO_DATE('2006-05', 'YYYY-MM') FROM DUAL
SELECT TO_DATE('2006', 'YYYY') FROM DUAL

Date Description:
When the input parameter is omitted HH, MI and the corresponding SS, Oracle use 0 as the DEFAULT value. If the date data input omit the time portion, when Oracle will, minute, and second parts are set to 0, that will be rounded to day.

Similarly, ignoring the DD parameters, Oracle will use the default value of 1 as the day, that will be rounded to month.

But do not be this kind of "inertia" confused, if ignored MM parameter, Oracle will not take the whole year, rounded to the current month.

Note:
As a format conversion "ss yyyy-MM-dd HH :: mm" format, but will cause errors in the Oracle: 1. When using Oracle to_date date conversion function to do, may be employed intuitively "ORA 01810 format code appears twice. " Such as: select to_date ( '2005-01-01 13:14:20' , 'yyyy-MM-dd HH24: mm: ss') from dual; because SQL case-insensitive, MM, and mm is considered to be the same format code, using Oracle's SQL mi instead of minutes. TO_DATE SELECT ( '2005-01-01 13:14:20', 'the MM-dd-YYYY HH24: mi The: SS') from Dual;
2. Another use HH24 be displayed in the form of a 24-hour
select to_char (sysdate , 'yyyy-mM-dd HH24 : mi: ss') from dual; // mi is minutes
select to_char (sysdate, 'yyyy- mM-dd HH24: mm: ss') from dual; // mm displays the month


TO_DATE format (time: 2007-11-02 13:45:25 for example)

Year:
YY TWO digits show the value of two years: 07
yyy Three digits in three display values: 007
yyyy four years at Four digits displayed value: 2007

month:
mm Number The two-month display value: 11
Mon Abbreviated character set displayed value: 11 months, if the English version, the display nov
month The spelled OUT character set displayed value: 11 months, if the English version, show november

Day:
dd The first few days of the month number displayed value: 02
ddd day of the year number displayed value: 02
dy abbreviated day of the week abbreviated display value: Friday, if the English version, displayed Fri
Day spelled OUT write full day of the week display value : Friday, if the English version, the display friday is created
ddspth spelled OUT, ORDINAL Twelfth

Hour:
HH TWO 12 Xiaoshi hexadecimal value displayed digits: 01
HH24 TWO 24-Xiaoshi hexadecimal digits displayed value: 13

Minute:
mi TWO 60 hexadecimal digits displayed value: 45

Second:
SS TWO 60 hexadecimal digits displayed value: 25

Other
Q quarter digit display value:. 4
WW of the week display digit year value: 44 is
W is the week of the month digit display value: 1

at the time range of 24-hour format: 0:00:00 - 23:59:59 ... .
time in the range of 12-hour format: 1:00:00 - 12:59:59 ....

1. date and character conversion function usage (TO_DATE, TO_CHAR)

SELECT TO_CHAR (SYSDATE, 'YYYY-mm-dd HH24: mi: ss') as nowTime from dual; // date into a string
select to_char (sysdate, 'yyyy' ) as nowYear from dual; // Get the time of
select to_char (sysdate, 'mm' ) as nowMonth from dual ; // Get month period
select to_char (sysdate, 'dd' ) as nowDay from dual; // Get the time of day of the
select to_char (sysdate, 'hh24' ) as nowHour from dual; // Get the time when the
select to_char ( sysdate, 'mi') as nowMinute from dual; // Get the time division
select to_char (sysdate, 'ss' ) as nowSecond from dual; // sec acquisition time

select to_date('2004-05-07 13:23:44','yyyy-mm-dd hh24:mi:ss') from dual//

2.
select to_char( to_date(222,'J'),'Jsp') from dual

显示Two Hundred Twenty-Two

3. The day of the week seeking
select to_char (to_date ( '2002-08-26' , 'yyyy-mm-dd'), 'day') from dual;
Monday
select to_char (to_date ( '2002-08-26 ',' YYYY-mm-dd '),' Day ',' American NLS_DATE_LANGUAGE = ') from Dual;
Monday
set the date language
ALTER SESSION sET NLS_DATE_LANGUAGE =' AMERICAN ' ;
can be so
TO_DATE (' 2002-08-26 ', 'YYYY-mm-dd', 'NLS_DATE_LANGUAGE = American')

4. The number of days between two dates
select floor (sysdate - to_date ( ' 20020405', 'yyyymmdd')) from dual;

The usage time is null
SELECT ID, active_date table1 from
the UNION
SELECT. 1, the TO_DATE (null) from Dual;

pay attention to use the TO_DATE (null)

6. month difference
a_date between to_date ( '20011201', 'yyyymmdd') and to_date ( '20011231', 'yyyymmdd')
then, after December 31 12:00 and before 12:00 on December 1 is not included in this within the range.
So, when the time requires precise, feel to_char still necessary

7. Date format conflicts
input format depends on the type of character set you install ORACLE, such as: type US7ASCII, date format is: '01 -Jan-01 '
ALTER System SET NLS_DATE_LANGUAGE = American
ALTER SET NLS_DATE_LANGUAGE = American the session
or the write to_date
select to_char (to_date (' 2002-08-26 ' ,' yyyy-mm-dd '),' day ',' NLS_DATE_LANGUAGE = American ') from dual;
pay attention to me this is just a NLS_DATE_LANGUAGE, of course, there are many,
you can view
the SELECT * from nls_session_parameters
the SELECT * from V $ NLS_PARAMETERS

8. The
SELECT COUNT (*)
from (SELECT rownum-RNUM. 1
from the all_objects
WHERE rownum & lt; = TO_DATE ( '2002-02-28', 'YYYY-mm-dd') - TO_DATE ( '2002-
02-01', 'YYYY-mm-dd') +. 1
)
WHERE TO_CHAR (TO_DATE ( '2002-02-01', 'YYYY-mm-dd') +-RNUM. 1, 'D')
Not in ( '. 1', '. 7 ')

Find 2002-02-28 to 2002-02-01 in addition to the number of days between Monday and seven
before and after the call DBMS_UTILITY.GET_TIME respectively, so that the result after subtraction (get is 1/100 seconds, not milliseconds).

9. 查找月份
select months_between(to_date('01-31-1999','MM-DD-YYYY'),to_date('12-31-1998','MM-DD-YYYY')) & quot;MONTHS" FROM DUAL;
1
select months_between(to_date('02-01-1999','MM-DD-YYYY'),to_date('12-31-1998','MM-DD-YYYY')) & quot;MONTHS" FROM DUAL;
1.03225806451613

10. Next_day的用法
Next_day(date, day)

Monday-Sunday, for format code DAY
Mon-Sun, for format code DY
1-7, for format code D

. 11
SELECT TO_CHAR (SYSDATE, 'HH: mi The: SS') from the all_objects the TIME
NOTE: TIME last line of the first record is the same
may establish a function to deal with this problem
Create Replace function or return DATE IS sys_date
the begin
return SYSDATE ;
End;

SELECT TO_CHAR (sys_date, 'HH: mi the: SS') from the all_objects;

number 12 hour obtained
extract () to find out the date interval value or field values
SELECT EXTRACT (hOUR fROM TIMESTAMP '2001-02-16 2: 38:40 ') the offer from
the SQL & gt; SELECT SYSDATE, TO_CHAR (SYSDATE,' HH ') from Dual;

SYSDATE the TO_CHAR (SYSDATE,' HH ')
------------------ - ---------------------
2003-10-13 19:35:21 07

the SQL & gt; SELECT SYSDATE, TO_CHAR (SYSDATE, 'HH24') from Dual;

SYSDATE TO_CHAR (SYSDATE, 'HH24' )
-------------------- -----------------------
2003-10-13 19:35:21 19


13.年月日的处理
select older_date,
newer_date,
years,
months,
abs(
trunc(
newer_date-
add_months( older_date,years*12+months )
)
) days

from ( select
trunc(months_between( newer_date, older_date )/12) YEARS,
mod(trunc(months_between( newer_date, older_date )),12 ) MONTHS,
newer_date,
older_date
from (
select hiredate older_date, add_months(hiredate,rownum)+rownum newer_date
from emp
)
)

14. The process variable approaches the number of days the month
select to_char (add_months (last_day (sysdate ) +1, -2), 'yyyymmdd'), last_day (sysdate) from dual

16. This year's find out the number of days
select add_months (trunc (sysdate, ' year'), 12) - trunc (sysdate, 'year') from dual

Leap approach
to_char (last_day (to_date ('02 ' | |: year,' mmyyyy ')),' dd ')
if it is not a leap year is 28

The difference 17.yyyy and rrrr
'YYYY99 TO_C
------- ----
yyyy 99 0099
rrrr 99 1999
yyyy 01 0001
rrrr 01 2001

18. Processing time zones
SELECT TO_CHAR (the NEW_TIME (SYSDATE, 'GMT', 'the EST'), 'dd / mm / YYYY HH: mi The: SS'), SYSDATE
from Dual;

A 19.5 second interval
the Select the TO_DATE (the FLOOR (the TO_CHAR (SYSDATE, 'SSSSS') / 300) * 300, 'SSSSS'), the TO_CHAR (SYSDATE, 'SSSSS')
from Dual

9:55:00 35786 2002-11-1
SSSSS represent five the number of seconds

20. The day of the year
SELECT the TO_CHAR (SYSDATE, 'DDD'), Dual SYSDATE from

310 2002-11-6 10:03:51

21.计算小时,分,秒,毫秒
select
Days,
A,
TRUNC(A*24) Hours,
TRUNC(A*24*60 - 60*TRUNC(A*24)) Minutes,
TRUNC(A*24*60*60 - 60*TRUNC(A*24*60)) Seconds,
TRUNC(A*24*60*60*100 - 100*TRUNC(A*24*60*60)) mSeconds
from
(
select
trunc(sysdate) Days,
sysdate - trunc(sysdate) A
from dual
)


* from tabname SELECT
Order by decode (MODE, 'the FIFO',. 1, -1) * TO_CHAR (RQ, 'YYYYMMDDHH24MISS');

//
Floor ((DATE2-date1) / 365) in a
floor ((date2-date1, 365) / 30) months as
d (mod (date2-date1, 365), 30) a day.

23.next_day function returns next week's date, day 1-7 or Sunday - Saturday, 1 Sunday
next_day (sysdate, 6) from the current start a Friday. The latter figure is counted from the beginning on Sunday.
1,234,567
Day one hundred twenty-three thousand four hundred fifty-six

------------------------------------ ---------------------------

SELECT (SYSDATE-TO_DATE ( '2003-12-03 12:55:45', 'YYYY-mm -dd hh24: mi: ss') ) * 24 * 60 * 60 from ddual
returned date is the day then converted into SS

24, round [rounded to the nearest date] (day: rounded to the nearest Sunday)
SYSDATE Sl SELECT,
round (SYSDATE) S2,
round (SYSDATE, 'year') yEAR,
round (SYSDATE, 'month The') MONTH,
round (SYSDATE, 'Day') from Dual DAY

25, trunc [truncated to the nearest date in days], returns a date type
SELECT SYSDATE Sl,
the trunc (SYSDATE) S2, // returns the current date, the minutes and seconds without
trunc (sysdate, 'year') YEAR, // returns the current year January 1, minutes and seconds when no
trunc (sysdate, 'month') mONTH, // returns the current month on the 1st, no minutes and seconds
trunc (sysdate, 'day') DAY // returns the current week Sunday, free minutes and seconds
from dual

26, the latest date return date list
select greatest ('01 - January -04 ',' dated -04 04-1 ',' Oct-Feb -04 ') from dual

27. The time difference calculating
NOTE: oracle is a time difference in units of days, so in terms of year, month, day

select floor (to_number (sysdate-to_date ( '2007-11-02 15:55:03', 'yyyy-mm-dd hh24: mi: ss')) / 365 ) as spanYears from dual

//时间差-年
select ceil(moths_between(sysdate-to_date('2007-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))) as spanMonths from dual

//时间差-月
select floor(to_number(sysdate-to_date('2007-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))) as spanDays from dual

//时间差-天
select floor(to_number(sysdate-to_date('2007-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))*24) as spanHours from dual

//时间差-时
select floor(to_number(sysdate-to_date('2007-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))*24*60) as spanMinutes from dual

//时间差-分
select floor(to_number(sysdate-to_date('2007-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))*24*60*60) as spanSeconds from dual

// time difference - seconds

28. Updated
NOTE: oracle add or subtract the number of days is a unit amount of change set to n, so in terms of year, month, day
select to_char (sysdate, 'yyyy- mm-dd hh24: mi: ss'), to_char (sysdate + n * 365, 'yyyy- mm-dd hh24: mi: ss') as newTime from dual

//改变时间-年
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),add_months(sysdate,n) as newTime from dual

//改变时间-月
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),to_char(sysdate+n,'yyyy-mm-dd hh24:mi:ss') as newTime from dual

//改变时间-日
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),to_char(sysdate+n/24,'yyyy-mm-dd hh24:mi:ss') as newTime from dual

//改变时间-时
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),to_char(sysdate+n/24/60,'yyyy-mm-dd hh24:mi:ss') as newTime from dual

//改变时间-分
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),to_char(sysdate+n/24/60/60,'yyyy-mm-dd hh24:mi:ss') as newTime from dual

// change the time - seconds

29.查找月的第一天,最后一天
SELECT Trunc(Trunc(SYSDATE, 'MONTH') - 1, 'MONTH') First_Day_Last_Month,
Trunc(SYSDATE, 'MONTH') - 1 / 86400 Last_Day_Last_Month,
Trunc(SYSDATE, 'MONTH') First_Day_Cur_Month,
LAST_DAY(Trunc(SYSDATE, 'MONTH')) + 1 - 1 / 86400 Last_Day_Cur_Month
FROM dual;

Guess you like

Origin www.cnblogs.com/ximi07/p/11956906.html