Functions and applications of date and time in DB2

Source: Internet
Author: User
Tags date current time db2 integer range

Dayname returns a mixed case string, with a week representing the name of the day (for example, Friday) for the day portion of the parameter.

DayOfWeek returns the number of days of the week in the argument, expressed as an integer value of 1-7, of which 1 represents Sunday.

Dayofweek_iso returns the number of days of the week in the argument, expressed as an integer value of 1-7, of which 1 represents Monday.

DayOfYear returns the day ordinal of a year in a parameter, expressed as an integer value of 1-366.

Days returns an integer representation of the date.

Julian_day returns the number of days between the specified date values in the parameter from January 1, 4712 BC (the start date of the Julian calendar), represented by an integer value.

Midnight_seconds returns the number of seconds between midnight and the time value specified in the parameter, represented by an integer value ranging from 0 to 86400.

MonthName returns a case-sensitive string (for example, January) for the month portion of the parameter.

Timestamp_iso returns a timestamp value based on a date, time, or time stamp parameter.

Timestamp_format returns a time stamp from a string that has been interpreted with a character template.

Timestampdiff The estimated slack represented by the type defined by the first parameter, based on the time difference between two timestamps.

To_char returns the character representation of a timestamp that has been formatted with a character template. To_char is synonymous with Varchar_format.

To_date returns a time stamp from a string that has been interpreted with a character template. To_date is synonymous with Timestamp_format.

WEEK returns the week ordinal of a year in a parameter, expressed as an integer value of range 1-54. Take Sunday as the beginning of a week.

Week_iso returns the week ordinal of a year in a parameter, expressed as an integer value of range 1-53.

To adjust the current time or the current time stamp to Gmt/cut, subtract the current time or time stamp from the current timezone register:

current time - current timezone
current timestamp - current timezone

Given a date, time, or time stamp, use the appropriate function to extract, if applicable, the year, month, day, time, minute, second, and microsecond sections:

YEAR (current timestamp)
MONTH (current timestamp)
DAY (current timestamp)
HOUR (current timestamp)
MINUTE (current timestamp)
SECOND (current timestamp)
MICROSECOND (current timestamp)

Because there are no better terms, you can also use English to perform date and time calculations:

current date + 1 YEAR
current date + 3 YEARS + 2 MONTHS + 15 DAYS
current time + 5 HOURS - 3 MINUTES + 10 SECONDS

Extracting dates and times individually from time stamps is also very simple:

DATE (current timestamp)
TIME (current timestamp)

The following example describes how to obtain the current timestamp of microsecond partial zeroing:

CURRENT TIMESTAMP - MICROSECOND (current timestamp) MICROSECONDS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.