Dear readers of our blog, we'd like to recommend you to visit the main page of our website, where you can learn about our product SQLS*Plus and its advantages.
 
SQLS*Plus - best SQL Server command line reporting and automation tool! SQLS*Plus is several orders of magnitude better than SQL Server sqlcmd and osql command line tools.
 

REQUEST COMPLIMENTARY SQLS*PLUS LICENCE

Enteros UpBeat offers a patented database performance management SaaS platform. It proactively identifies root causes of complex revenue-impacting database performance issues across a growing number of RDBMS, NoSQL, and deep/machine learning database platforms. We support Oracle, SQL Server, IBM DB2, MongoDB, Casandra, MySQL, Amazon Aurora, and other database systems.

PostgreSQL to_timestamp function

3 September 2020

PostgreSQL to_timestamp function

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.
ParameterExplanation
YYYY4-digit year
Y,YYY4-digit semicolon year
YYY  YY

  Y

Last 3, 2 or 1 digit (and) years
IYYYThe 4-digit year according to ISO standard
IYY  IY

  I

Last 3, 2 or 1 digit(s) of ISO year
QA quarter of the year (1, 2, 3, 4; JAN-MAR = 1)
ММMonth (01-12; JAN = 01)
MONAbbreviated name of a month in upper case
MonAbbreviated name of the month with a capital letter
monAbbreviated name of a month in lower case
MONTHThe name of the month in capital letters, completed with spaces up to 9 characters long
MonthThe name of the month with a capital letter, supplemented with spaces up to 9 characters long
monthThe name of the month in lowercase letters, supplemented with spaces up to 9 characters long
RMOne month with Roman numerals
rmMonth in lowercase Roman numerals
WWWeek of the year (1-53), where week 1 begins on the first day of the year
WWeek of the month (1-5), where week 1 begins on the first day of the month
IWISO Week of the year (01-53)
DAYThe name of the day in capital letters, completed with spaces up to 9 characters long
DayThe name of the day with a capital letter, completed with spaces up to 9 characters long
dayThe name of the day in lowercase letters, completed with spaces up to 9 characters long
DYAbbreviated name of the day in upper case
DyAbbreviated name of the day with a capital letter
dyAbbreviated name of the day in lowercase letters
DDDDay of the year (1-366)
IDDDDay of the year based on ISO year
DDDay of the month (01-31)
DDay of the week (1-7, where 1 = Sunday, 7 = Saturday)
IDDay of the week based on ISO year (1-7, where 1 = Monday, 7 = Sunday)
JJulian day; the number of days from midnight November 24, 4714 BC.
HHOne o’clock of the day (01-12)
HH12One o’clock of the day (01-12)
HH24One o’clock of the day (00-23)
MIOne minute (00-59)
SSA second (00-59)
MSMillisecond (000-999)
USMicrosecond (000000-999999)
SSSSSeconds after midnight (0-86399)
am, AM, pm, or PMMeridian Indicator
a.m., A.M., p.m., or P.M.Meridian Indicator
ad, AD, a.d., or A.DAD indicator
bc, BC, b.c., or B.C.BC Indicator
TZName of the time zone in upper case
tzName of the time zone in lower case
CC2-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

 
Tags: , , , ,

MORE NEWS

 

Preamble​​NoSql is not a replacement for SQL databases but is a valid alternative for many situations where standard SQL is not the best approach for...

Preamble​​MongoDB Conditional operators specify a condition to which the value of the document field shall correspond.Comparison Query Operators $eq...

5 Database management trends impacting database administrationIn the realm of database management systems, moreover half (52%) of your competitors feel...

The data type is defined as the type of data that any column or variable can store in MS SQL Server. What is the data type? When you create any table or...

Preamble​​MS SQL Server is a client-server architecture. MS SQL Server process starts with the client application sending a query.SQL Server accepts,...

First the basics: what is the master/slave?One database server (“master”) responds and can do anything. A lot of other database servers store copies of all...

Preamble​​Atom Hopper (based on Apache Abdera) for those who may not know is an open-source project sponsored by Rackspace. Today we will figure out how to...

Preamble​​MongoDB recently introduced its new aggregation structure. This structure provides a simpler solution for calculating aggregated values rather...

FlexibilityOne of the most advertised features of MongoDB is its flexibility.  Flexibility, however, is a double-edged sword. More flexibility means more...

Preamble​​SQLShell is a cross-platform command-line tool for SQL, similar to psql for PostgreSQL or MySQL command-line tool for MySQL.Why use it?If you...

Preamble​​Writing an application on top of the framework on top of the driver on top of the database is a bit like a game on the phone: you say “insert...

Preamble​​Oracle Coherence is a distributed cache that is functionally comparable with Memcached. In addition to the basic function of the API cache, it...

Preamble​​IBM pureXML, a proprietary XML database built on a relational mechanism (designed for puns) that offers both relational ( SQL / XML ) and...

  What is PostgreSQL array? In PostgreSQL we can define a column as an array of valid data types. The data type can be built-in, custom or enumerated....

Preamble​​If you are a Linux sysadmin or developer, there comes a time when you need to manage an Oracle database that can work in your environment.In this...

Preamble​​Starting with Microsoft SQL Server 2008, by default, the group of local administrators is no longer added to SQL Server administrators during the...