Date and time storage and format conversion

In the previous article, we introduced the common character functions in SQL, and learned how to connect text data, convert between upper and lower case, and find and replace substrings.

In this article, we continue to discuss common date and time functions, as well as conversion functions between different data types.

Date and time storage

In the database, there are three forms of date and time types:

  • DATE , date type, including year, month, and day. Can be used to store date of birth, date of entry, etc.
  • TIME , the time type, including hours, minutes, seconds, and fractional seconds. Generally used less.
  • TIMESTAMP , a timestamp type, including year, month, day, hour, minute, second, and fractional seconds. Used for scenarios that require high time accuracy, such as storing order time.

TIMESTAMP and TIME can also add WITH TIME ZONE option to specify a time zone offset. For example, 0 o'clock in UTC standard time is equal to 8 o'clock in the morning in Beijing time. Time zone options are usually used in applications that support globalization.

The following is the support situation of 4 kinds of databases for date and time types.

type of data Oracle MySQL SQL Server PostgreSQL
DATE Contains additional hours, minutes, and seconds stand by stand by stand by
TIME not support Support, not support time zone Support, not support time zone support

Guess you like

Origin blog.csdn.net/horses/article/details/108729108