EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL Current Date

PostgreSQL Current Date

Sohel Sayyad
Article bySohel Sayyad
Priya Pedamkar
Reviewed byPriya Pedamkar

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.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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
PROGRAMMING LANGUAGES Course Bundle - 54 Courses in 1 | 4 Mock Tests
338+ Hours of HD Videos
54 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
SELENIUM Course Bundle - 15 Courses in 1 | 9 Mock Tests
39+ Hours of HD Videos
15 Courses
9 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
IOT System Course Bundle - 7 Courses in 1
43+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
JENKINS Course Bundle - 6 Courses in 1
15+ Hour of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Popular Course in this category
POSTGRESQL Course Bundle - 5 Courses in 1 | 1 Mock Test
 15+ Hour of HD Videos
5 Courses
1 Mock Tests & Quizzes
  Verifiable Certificate of Completion
  Lifetime Access
4.5
Price

View Course
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • 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

ISO 10004:2018 & ISO 9001:2015 Certified

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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

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

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

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

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

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more