The previous article introduced the installation of the DB2 database. This article will introduce youCommon date operation functions of DB2 Databases. Provides knowledge for you to learn about the DB2 database.
Db2 date operation functions
Current Time:
CURRENT DATE
CURRENT TIME
CURRENT TIMESTAMP
Obtain the year, month, day, hour, minute, second, And microsecond parts of the time:
YEAR (current timestamp)
MONTH (current timestamp)
DAY (current timestamp)
HOUR (current timestamp)
MINUTE (current timestamp)
SECOND (current timestamp)
MICROSECOND (current timestamp)
Addition and subtraction of time:
Current date + 1 YEAR
Current date + 3 YEARS + 2 MONTHS + 15 DAYS
Current time + 5 HOURS-3 MINUTES + 10 SECONDS
To calculate the number of days between two dates, you can subtract the date:
Days (current date)-days (date ('2017-10-22 '))
Convert time to string:
Char (current date)
String to time:
TIMESTAMP (), DATE (), and TIME (). For supported string formats, see help. oracle to_date is not flexible.
Date ('2014-01-01 ')
Some functions of date and time:
DAYNAME returns a string of both upper and lower cases. For the day part of the parameter, the name of the day (for example, Friday) is expressed by week ).
DAYOFWEEK returns the day of the week in the parameter, expressed by an integer ranging from 1 to 7, where 1 represents Sunday.
DAYOFWEEK_ISO returns the day of the week in the parameter, expressed by an integer ranging from 1 to 7, where 1 represents Monday.
DAYOFYEAR returns the day of the year in the parameter, expressed by an integer ranging from 1 to 366.
DAYS returns an integer of the date.
JULIAN_DAY returns the number of days from January 1, January 1, 4712 BC (the start date of the Confucian calendar) to the specified date value in the parameter, expressed in an integer.
MIDNIGHT_SECONDS returns the number of seconds between midnight and the specified time value in the parameter, which is expressed by an integer ranging from 0 to 86400.
MONTHNAME returns a string (for example, January) with a mix of upper and lower cases for the Month of the parameter ).
TIMESTAMP_ISO returns a time stamp Value Based on the date, time, or time stamp parameter.
TIMESTAMP_FORMAT returns a timestamp from a string interpreted using a character template.
TIMESTAMPDIFF returns the estimated time difference expressed by the type defined by the first parameter based on the time difference between the two timestamps.
TO_CHAR returns the time stamp character representation formatted using the character template. TO_CHAR is a synonym for VARCHAR_FORMAT.
TO_DATE returns a timestamp from a string that has been interpreted using a character template. TO_DATE is a synonym for TIMESTAMP_FORMAT.
WEEK returns the WEEK number of the year in the parameter, expressed by an integer ranging from 1 to 54. Start from Sunday.
WEEK_ISO returns the week of the year in the parameter, which is expressed by an integer ranging from 1 to 53.
Having mastered the daily date operation functions of these DB2 databases, it will be easy to compile them later. I am very happy to share with you the commonly used date operation functions of the DB2 database, hope to help you.