EDUCBA

EDUCBA

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

DB2 current date

Secondary Sidebar
DB2 Tutorial
  • DB2 Tutorial
    • What is DB2?
    • DB2? current date
    • DB2 purescale
    • DB2 backup
    • DB2 restore
    • DB2 C Express
    • DB2 Version
    • DB2? Architecture
    • DB2? Data Types
    • DB2? load
    • DB2? order by
    • DB2 date
    • DB2 NVL
    • DB2? update
    • DB2 warehouse
    • DB2 grant
    • DB2 database
    • DB2 VARCHAR
    • DB2? INSERT
    • DB2 LISTAGG
    • DB2 LIKE
    • DB2 TRUNCATE TABLE
    • DB2 LIST TABLES
    • DB2 between
    • DB2? current timestamp
    • DB2? length
    • DB2? bind
    • DB2 limit rows
    • DB2? export
    • DB2 with
    • DB2 Create Table
    • DB2 case statement
    • DB2 CAST
    • DB2 Functions
    • DB2 Date Functions
    • DB2? row_number
    • DB2 trim
    • DB2? Translate
    • DB2 UNION
    • DB2 timestamp
    • DB2? TIMESTAMPDIFF
    • DB2? replace
    • DB2 merge
    • DB2 COALESCE
    • DB2 ISNULL
    • DB2? explain
    • DB2 Join
    • DB2 alter column
    • DB2 rename column
    • DB2? Describe Table
    • DB2? rename table
    • DB2 List Databases
    • DB2 LUW
    • DB2 Query
    • DB2 GROUP BY
    • DB2 TO_DATE
Home Data Science Data Science Tutorials DB2 Tutorial DB2 current date

DB2 current date

Introduction to DB2 current date

Database management systems provide a different kind of function to the user; the current date () function is one of the functions that is provided by the DB2 to the users. It is one kind of special register that is useful to fetch the system’s current date when we execute the SQL statement on the server. Basically, DB2 current date () function depends on the clock of the system. The CURRENT DATE () is a function that we called a special register, and it is used for more than one time within a specified SQL statement to return the  CURRENT DATE or CURRENT TIME by using a single SQL statement.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,938 ratings)

Syntax

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

select current date from the system table or specified table;

Explanation

In the above, we use the current date () function to return the current system date; in this syntax, we can also use a system table that contains the value of the DB2 register, as well as we can also use this function with different clauses as per the requirement.

How DB2 current date function works?

Now let’s see how the current date () function works in DB2 as follows.

Basically, we can use different parameters for the current date () function as follows.

Year: It is used to return the current year.

Month: It is used to return the current month.

Day: It is used to return to the current day.

Day Name: This is used to return the day of the date.

Dayofyear:  It is used to return the day of the year.

The CURRENT DATE exceptional register determines a current date that depends on a system date when the SQL statement will be executed on the current server.

On the off chance that this unique register is utilized more than one time inside a solitary SQL statement or utilized with CURRENT DATE or CURRENT TIME inside a solitary proclamation, all qualities depend on a solitary clock reading.

The estimation of CURRENT DATE in a client characterized work or put away strategy is acquired by using the standards.

Indicating CURRENT DATE is identical to determining CURRENT DATE. On the off chance that you need a timestamp with a predetermined accuracy, the extraordinary register can be referred to as CURRENT DATE(integer), where the whole number can go 0 – 12. The default accuracy is 6. SYSDATE can likewise be determined as an equivalent word for CURRENT DATE.

Examples of DB2 current date

Now let’s see the different examples of the current time to better understand as follows.

First, we need to create a database and table by using the following statement as follows.

create databases up;

Explanation

In the above example, we create a database statement to create a new database name. After that, we need to connect the database by using the following command as follows.

connect to up

Explanation

The end out we illustrate by using the following screenshot as follows.

DB2 current date output 1

Now perform the current date () function as follows.

SELECT CURRENT DATE FROM SYSIBM.SYSDUMMY1

Explanation

In the above example, we use the current date function to fetch the current date from the sysdummy1 table that is created inside the sysibm database. Basically, those are system-created databases and tables. The end out we illustrate by using the following screenshot as follows.

DB2 current date output 2

Suppose we need to know what yesterday’s data is at that time; we can use the following statement as follows.

select date ( days( current date) -1 ) yesterday_date from sysibm.sysdummy1

Explanation

In the above example, we use a select clause with the current date function; see here day-1 to determine the yesterday date from the sysdummy1 table that is created inside the sysibm database. Basically, those are system-created databases and tables. The end out we illustrate by using the following screenshot as follows.

DB2 current date output 3

In the same way, we can determine tomorrow’s date by using the same statement; we just need to use day+1 instead of day-1 as follows.

select date ( days( current date) +1 ) tommarow_date from sysibm.sysdummy1

Explanation

In the above example, we use a select clause with the current data function; see here we day+1 to determine tomorrow’s date from the sysdummy1 table that is created inside the sysibm database. Basically, those are system-created databases and tables. The end out we illustrate by using the following screenshot as follows.

output 4

Suppose we need to calculate the difference between the two dates at that time; we can use the following statement as follows.

SELECT (current date) - date(2020-05-03) FROM sysibm.sysdummy1

Explanation

In the above example, we try to find out the difference between the two different dates here. We use the current date function () with the second date. In this example, we perform the subtraction operation to determine the difference between the two dates from the sysdummy1 table that is created inside the sysibm database. Basically, those are system-created databases and tables. The end out we illustrate by using the following screenshot as follows.

output 5

Suppose we need to determine the current day at that time; we can use the following statement as follows.

SELECT (day(current date))present_day FROM sysibm.sysdummy1

Explanation

In the above example, we use the current date function with the day parameter, as shown in the above statement, from the sysdummy1 table that is created inside the sysibm database. Basically, those are system-created databases and tables. The end out we illustrate by using the following screenshot as follows.

output 6

Similarly, we can calculate month and year as follows.

SELECT (month(current date))present_month FROM sysibm.sysdummy1

Explanation

The end out we illustrate by using the following screenshot as follows.

 output 7

The same function that is the current date function () we can apply on the user-created table.

So in this way, we can use the current date function as per the user requirement.

Conclusion

We hope from this article you learn the DB2 current date functions. From the above article, we have learned the basic syntax of a current date function, and we also see different examples of the current date function. Furthermore, from this article, we learned how and when we use the DB2 current date function.

Recommended Articles

This is a guide to DB2 current date. Here we discuss the basic syntax of a current date function and see different examples of the current date function. You may also have a look at the following articles to learn more –

  1. DB2 case statement
  2. DB2 Version
  3. DB2 INSERT
  4. DB2 LISTAGG
Popular Course in this category
SQL Training Program (7 Courses, 8+ Projects)
  7 Online Courses |  8 Hands-on Projects |  73+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • 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

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

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

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

EDUCBA Login

Forgot Password?

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

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

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

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

Let’s Get Started

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

Special Offer - SQL Training Program (7 Courses, 8+ Projects) Learn More