Preamble
The PostgreSQL to_timestamp function converts a string into a timestamp.
Syntax of the to_timestamp function in PostgreSQL
to_timestamp( string1, format_mask )
Parameters and function arguments
- string1 – String that will be converted to timestamp.
- format_mask – The format that will be used to convert string1 to timestamp. This can be one of the following and can be used in many combinations.
| Parameter | Explanation |
| YYYY | 4-digit year |
| Y,YYY | 4-digit semicolon year |
| YYY YY Y |
Last 3, 2 or 1 digit (and) years |
| IYYY | The 4-digit year according to ISO standard |
| IYY IY I |
Last 3, 2 or 1 digit(s) of ISO year |
| Q | A quarter of the year (1, 2, 3, 4; JAN-MAR = 1) |
| ММ | Month (01-12; JAN = 01) |
| MON | Abbreviated name of a month in upper case |
| Mon | Abbreviated name of the month with a capital letter |
| mon | Abbreviated name of a month in lower case |
| MONTH | The name of the month in capital letters, completed with spaces up to 9 characters long |
| Month | The name of the month with a capital letter, supplemented with spaces up to 9 characters long |
| month | The name of the month in lowercase letters, supplemented with spaces up to 9 characters long |
| RM | One month with Roman numerals |
| rm | Month in lowercase Roman numerals |
| WW | Week of the year (1-53), where week 1 begins on the first day of the year |
| W | Week of the month (1-5), where week 1 begins on the first day of the month |
| IW | ISO Week of the year (01-53) |
| DAY | The name of the day in capital letters, completed with spaces up to 9 characters long |
| Day | The name of the day with a capital letter, completed with spaces up to 9 characters long |
| day | The name of the day in lowercase letters, completed with spaces up to 9 characters long |
| DY | Abbreviated name of the day in upper case |
| Dy | Abbreviated name of the day with a capital letter |
| dy | Abbreviated name of the day in lowercase letters |
| DDD | Day of the year (1-366) |
| IDDD | Day of the year based on ISO year |
| DD | Day of the month (01-31) |
| D | Day of the week (1-7, where 1 = Sunday, 7 = Saturday) |
| ID | Day of the week based on ISO year (1-7, where 1 = Monday, 7 = Sunday) |
| J | Julian day; the number of days from midnight November 24, 4714 BC. |
| HH | One o’clock of the day (01-12) |
| HH12 | One o’clock of the day (01-12) |
| HH24 | One o’clock of the day (00-23) |
| MI | One minute (00-59) |
| SS | A second (00-59) |
| MS | Millisecond (000-999) |
| US | Microsecond (000000-999999) |
| SSSS | Seconds after midnight (0-86399) |
| am, AM, pm, or PM | Meridian Indicator |
| a.m., A.M., p.m., or P.M. | Meridian Indicator |
| ad, AD, a.d., or A.D | AD indicator |
| bc, BC, b.c., or B.C. | BC Indicator |
| TZ | Name of the time zone in upper case |
| tz | Name of the time zone in lower case |
| CC | 2-digit century |
The to_timestamp function can be used in the following PostgreSQL versions
PostgreSQL 11, PostgreSQL 10, PostgreSQL 9.6, PostgreSQL 9.5, PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4.
Let’s look at some examples of to_timestamp functions to see how to use the to_timestamp function in PostgreSQL.
For example:
SELECT to_timestamp('2019/04/23', 'YYYY/MM/DD');
--Result: 2019-04-23 00:00:00+00
SELECT to_timestamp('2019/04/23 10:13', 'YYYY/MM/DD HH:MI');
--Result: 2019-04-23 10:13:00+00
SELECT to_timestamp('2019/04/23 10:13:18.041.394820', 'YYYY/MM/DD HH:MI:SS.MS.US');
--Result: 2019-04-23 10:13:18.18.43582+00
SELECT to_timestamp('10:13:18.041.394820', 'HH:MI:SS.MS.US');
--Result: 0001-01-01 10:13:18.18.43582+00 BC
Date functions in PostgreSQL , Time functions in PostgreSQL
About Enteros
Enteros offers a patented database performance management SaaS platform. It proactively identifies root causes of complex business-impacting database scalability and performance issues across a growing number of clouds, RDBMS, NoSQL, and machine learning database platforms.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
From Network Traffic to Cost Transparency: Enteros Approach to Amortized Cost Management in Telecom
- 12 February 2026
- Database Performance Management
Introduction Telecom operators today are no longer just connectivity providers. They are digital service platforms supporting 5G networks, IoT ecosystems, streaming services, cloud-native core systems, enterprise connectivity, and real-time analytics. Every call, message, streaming session, IoT signal, and digital interaction generates massive volumes of transactional and analytical data. That data is processed, stored, and monetized … Continue reading “From Network Traffic to Cost Transparency: Enteros Approach to Amortized Cost Management in Telecom”
From Transactions to Transparency: Enteros’ AI SQL Platform for Financial Database Performance and Cost Intelligence
Introduction In the financial sector, performance is not optional—it is existential. Banks, insurance providers, capital markets firms, fintech platforms, and payment processors operate in environments where milliseconds matter, compliance is mandatory, and financial transparency is critical. Every transaction—whether it’s a trade execution, loan approval, insurance claim, or digital payment—flows through complex database infrastructures. Yet as … Continue reading “From Transactions to Transparency: Enteros’ AI SQL Platform for Financial Database Performance and Cost Intelligence”
Driving Healthcare RevOps Efficiency with AI SQL–Powered Database Performance Management Software
- 11 February 2026
- Database Performance Management
Introduction Healthcare organizations today operate at the intersection of clinical excellence, regulatory compliance, and financial sustainability. Hospitals, health systems, payer organizations, and healthtech SaaS providers depend on digital platforms to manage electronic health records (EHRs), billing systems, revenue cycle management (RCM), patient portals, telehealth platforms, claims processing engines, and analytics tools. At the core of … Continue reading “Driving Healthcare RevOps Efficiency with AI SQL–Powered Database Performance Management Software”
Retail Revenue Meets Cloud Economics: Enteros AIOps-Driven Approach to Database Cost Attribution
Introduction Retail has become a real-time, data-driven industry. From omnichannel commerce and dynamic pricing engines to inventory optimization, loyalty platforms, recommendation systems, and last-mile logistics, modern retail runs on software—and software runs on databases. As retailers scale their digital presence, they increasingly rely on SaaS platforms, microservices architectures, hybrid cloud infrastructure, and distributed database environments. … Continue reading “Retail Revenue Meets Cloud Economics: Enteros AIOps-Driven Approach to Database Cost Attribution”