EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

PostgreSQL Current Date

By Sohel SayyadSohel Sayyad

Home » Data Science » Data Science Tutorials » PostgreSQL Tutorial » PostgreSQL Current Date

PostgreSQL Current Date

Definition of PostgreSQL Current Date

We can get the current date by using the PostgreSQL current_date function. The PostgreSQL current_date function does’t accept any arguments or parameters. Even if the PostgreSQL current_date is a function but it is not required to add parentheses () after the PostgreSQL current_date function. The PostgreSQL current_date function will return the current date which is in a ‘YYYY-MM-DD’ format. We can use the PostgreSQL current_date function with the versions of PostgreSQL such as PostgreSQL 8.4, PostgreSQL 9.0, PostgreSQL 9.1, PostgreSQL 9.2, PostgreSQL 9.3, and PostgreSQL 9.4 etc. The PostgreSQL current_date function will have different dates as per the execution date of the PostgreSQL current_date function.

How does the PostgreSQL Current_date function work?

As we know the PostgreSQL Current_date function returns the current date which is in a ‘YYYY-MM-DD’ format which means,

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

  • YYYY defines the year which is four-digit.
  • MM defines the month which is two-digit,
  • DD defines the day which is two-digit’

In order to understand the working of the PostgreSQL Current_date function, let’s consider the following examples of the PostgreSQL current_date function.

  1. Consider the following which will return the current date in ‘YYYY-MM-DD’ format.

SELECT current_date AS today_date;

Illustrate the result of the above statement by using the following snapshot:

PostgreSQL Current Date 1

In the above example we will get the format which works as follows :

  • YYYY defines the year which is four-digit ‘2020’,
  • MM defines the month which is two-digit ’05’,
  • DD defines the day which is two-digit ’29’
  1. We can perform arithmetic operations like add or subtracts on the current date, Consider the following example to understand the PostgreSQL current_date function with add or subtracts.

SELECT current_date + 2 AS two_plus_today_date;

Illustrate the result of the above statement by using the following snapshot:

PostgreSQL Current Date 2

In the above example we will get the format which works as follows :

  • YYYY defines the year which is four-digit ‘2020’,
  • MM defines the month which is two-digit ’05’,
  • DD defines the day which is two-digit ’31’

SELECT current_date - 2 AS two_minus_today_date;

Illustrate the result of the above statement by using following snapshot:

PostgreSQL Current Date 3

In the above example we will get the format which works as follows :

  • YYYY defines the year which is four-digit ‘2020’,
  • MM defines the month which is two-digit ’05’,
  • DD defines the day which is two-digit ’27’

In the above examples, we can see the PostgreSQL current_date function returns a current date by adding or subtracting days which is equal to the number mentioned after (-) or (+) sign.

  1. We can use the PostgreSQL current_date function in table creation as well. We can give default value to the column by using the PostgreSQL current_date function. The PostgreSQL current_date function will have different dates as per the execution date of the PostgreSQL current_date function.

Consider the following example where we will create a table named ‘Employee’ and this table will have column ‘joining_date’ with data type as DATE. The column ‘joining_date’ will have a default value set to the current date as we are using the PostgreSQL current_date function for setting a default value, and which is the result of the PostgreSQL current_date function.

Consider the following CREATE TABLE statement which will create a table named ‘Employee’.

CREATE TABLE Employee(
Employee_id serial PRIMARY KEY,
Employee_name varchar(255) NOT NULL,
joining_date DATE DEFAULT CURRENT_DATE
);

Now, we will insert a row into the Employee table by use the INSERT INTO statement as follows:

INSERT INTO Employee(Employee_name)
VALUES('Jacob Petter');

In the above INSERT INTO statement, we have not specified the joining date, hence the PostgreSQL sets default value as the current date.

Illustrate the result of the Employee table by using the following SQL statement and a snapshot.

SELECT * FROM Employee;

PostgreSQL Current Date 4

In the above example for the date of joining we have used CURRENT_DATE the format which works as follows :

  • YYYY defines the year which is four-digit ‘2020’,
  • MM defines the month which is two-digit ’05’,
  • DD defines the day which is two-digit ’29’

As per the SQL query execution date, the Employee table will have different dates inserted in the ‘joining_date’ column. Like, if someone is joining a company tomorrow and we execute the insert into a SQL statement as explained above the date of joining will be tomorrow’s date.

Conclusion – PostgreSQL Current Date

We hope from the above article you have understood how to use the PostgreSQL Current date and how the PostgreSQL PostgreSQL Current date works. Also, we have added several examples of PostgreSQL PostgreSQL Current date to understand it in detail.

Recommended Articles

This is a guide to PostgreSQL Current Date. Here we also discuss the Description, syntax, parameters, How does the PostgreSQL Current_date function work? and different examples, and its code implementation. You may also have a look at the following articles to learn more –

  1. PostgreSQL Link
  2. PostgreSQL SET
  3. PostgreSQL Integer
  4. PostgreSQL Character Varying

All in One Data Science Bundle (360+ Courses, 50+ projects)

360+ Online Courses

50+ projects

1500+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PostgreSQL Tutorial
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL log_statement
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL INTERSECT
    • PostgreSQL Like
    • Cursors in PostgreSQL
    • PostgreSQL UNION ALL
    • Indexes in PostgreSQL
    • PostgreSQL Index Types
    • PostgreSQL REINDEX
    • PostgreSQL UNIQUE Index
    • PostgreSQL Clustered Index
    • PostgreSQL DROP INDEX
    • PostgreSQL DISTINCT
    • PostgreSQL FETCH
    • PostgreSQL RAISE EXCEPTION
    • PostgreSQL Auto Increment
    • Sequence in PostgreSQL
    • Wildcards in PostgreSQL
    • PostgreSQL Subquery
    • PostgreSQL Alias
    • PostgreSQL LIMIT
    • PostgreSQL Limit Offset
    • PostgreSQL LAG()
    • PostgreSQL Table
    • Postgres Show Tables
    • PostgreSQL Describe Table
    • PostgreSQL Lock Table
    • PostgreSQL ALTER TABLE
    • Postgres Rename Table
    • Postgres DROP Table
    • PostgreSQL Functions
    • PostgreSQL Math Functions
    • PostgreSQL Window Functions
    • Aggregate Functions in PostgreSQL
    • PostgreSQL Primary Key
    • Foreign Key in PostgreSQL
    • PostgreSQL Procedures
    • PostgreSQL Stored Procedures
    • PostgreSQL Views
    • PostgreSQL Materialized Views
    • Postgres Create View
    • PostgreSQL Triggers
    • PostgreSQL DROP TRIGGER
    • PostgreSQL Date Functions
    • PostgreSQL TO_DATE()
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL RANK()
    • PostgreSQL Select
    • PostgreSQL Average
    • PostgreSQL DATE_PART()
    • PostgreSQL EXECUTE
    • PostgreSQL COALESCE
    • PostgreSQL EXTRACT()
    • PostgreSQL Sort
    • PostgreSQL TO_CHAR
    • PostgreSQL Interval
    • PostgreSQL Number Types
    • PostgreSQL ROW_NUMBER
    • Alter Column in PostgreSQL
    • PostgreSQL Identity Column
    • PostgreSQL SPLIT_PART()
    • PostgreSQL CONCAT()
    • PostgreSQL replace
    • PostgreSQL TRIM()
    • PostgreSQL MAX
    • PostgreSQL DELETE
    • PostgreSQL Float
    • PostgreSQL OID
    • PostgreSQL log
    • PostgreSQL REGEXP_MATCHES()
    • PostgreSQL MD5 
    • PostgreSQL NOW()
    • PostgreSQL RANDOM
    • PostgreSQL round
    • PostgreSQL Trunc()
    • PostgreSQL TIME
    • PostgreSQL IS NULL
    • PostgreSQL CURRENT_TIME
    • PostgreSQL MOD()
    • Postgresql Count
    • PostgreSQL Datetime
    • PostgreSQL MIN()
    • PostgreSQL age()
    • PostgreSQL enum
    • PostgreSQL OR
    • PostgreSQL Wal
    • PostgreSQL NOT IN
    • PostgreSQL SET
    • PostgreSQL Current Date
    • PostgreSQL Compare Date
    • PostgreSQL SERIAL
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Restore Database
    • PostgreSQL DROP DATABASE
    • PostgreSQL ALTER DATABASE
    • Postgres DROP Database
    • Postgres Dump Database
    • PostgreSQL OFFSET
    • PostgreSQL GRANT
    • PostgreSQL COMMIT
    • PostgreSQL ROLLUP
    • PostgreSQL JSON
    • EXPLAIN ANALYZE in PostgreSQL
    • PostgreSQL Temporary Table
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL DECODE()
    • PostgreSQL Vacuum
    • PostgreSQL EXCLUDE
    • Postgres Change Password
    • Postgres Delete Cascade
    • PostgreSQL EXCEPT
    • PostgreSQL Roles
    • PostgreSQL Link
    • PostgreSQL Partition
    • PostgreSQL column does not exist
    • PostgreSQL Log Queries
    • PostgreSQL escape single quote
    • PostgreSQL Query Optimization
    • PostgreSQL Character Varying
    • PostgreSQL Transaction
    • PostgreSQL Extensions
    • PostgreSQL Import CSV
    • PostgreSQL Client
    • PostgreSQL caching
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
  • Control Statement
    • PostgreSQL IF Statement
    • PostgreSQL if else
    • PostgreSQL CASE Statement
    • PostgreSQL LOOP
    • PostgreSQL For Loop
    • PostgreSQL While Loop
  • Joins
    • Joins in PostgreSQL
    • PostgreSQL Inner Join
    • PostgreSQL Outer Join
    • LEFT OUTER JOIN in PostgreSQL
    • PostgreSQL FULL OUTER JOIN
    • PostgreSQL LEFT JOIN
    • PostgreSQL Full Join
    • PostgreSQL Cross Join
    • PostgreSQL NATURAL JOIN
    • PostgreSQL UPDATE JOIN
  • Queries
    • PostgreSQL Queries
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - All in One Data Science Bundle (360+ Courses, 50+ projects) Learn More