EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL Current Date
 

PostgreSQL Current Date

Sohel Sayyad
Article bySohel Sayyad
EDUCBA
Reviewed byRavi Rathore

Updated May 18, 2023

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.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

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,

  • YYYY defines the year, which is four-digit.
  • MM defines the month which is two-digit,
  • DD defines the day on 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 the ‘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 a 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 a two-digit ’31.’
SELECT current_date - 2 AS two_minus_today_date;

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

Output 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 a 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 to set a default value, 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 using 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 currency symbol and a snapshot.

SELECT * FROM Employee;

Output 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

We hope that this EDUCBA information on “PostgreSQL Current Date” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

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

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA

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

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

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

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

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

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW