⌘BABAKOV.NET Let's code!
100% [light] [ru]

Oracle TO_DATE Function (PL/SQL)

The TO_DATE function converts a string to a DATE variable.

Syntax:

TO_DATE(исходная_строка, Формат, NLS_LANGUAGE);
--Последний параметр NLS_LANGUAGE (как я понимаю для задания кодировки) мне не разу не пригодился.


Examples:

SQL> select to_date(\'24.05.1980\',\'dd.mm.yyyy\') from dual;
 
TO_DATE(\'24.05.1980\',\'DD.MM.YY
------------------------------
24.05.1980
 
SQL> select to_date(\'24.05.1980 14:16:34\',\'dd.mm.yyyy hh24:mi:ss\') from dual;
 
TO_DATE(\'24.05.198014:16:34\',\'
------------------------------
24.05.1980 14:16:34



The format can be specified using combinations of the following values:

  • YYYY — Four-digit year (e.g. 1980)
  • YY — Two-digit year (e.g. 84)
  • Q — Quarter (1, 2, 3, 4)
  • MM — Month (01-12)
  • WW — Week number in year (1-53) where week 1 starts on the first day of the year and continues for 7 days
  • W — Week number in month (1-5) where week 1 starts on the first day of the month and continues for 7 days
  • IW — Week number in year (1-52 or 1-53) according to the ISO standard
  • D — Day of week (1-7)
  • DD — Day of month (1-31)
  • DDD — Day of year (1-366)
  • J — Day according to the Julian calendar, day number from January 1, 4712 BCE to CE
  • H — Hour (1-12)
  • HH12 — Hour (1-12)
  • HH24 — Hour (0-23)
  • MI — Minutes (0-59)
  • SS — Seconds (0-59)


This is probably the main parameters that will be useful.

Comments (0)

No comments yet.

Leave a comment
Comment
Images (up to 5 MB)
Your comment will appear after moderation.