Resources | Subject Notes | Information Communication Technology ICT
Be able to set the display format of date and time data within a database system.
Databases use specific data types to store date and time information. Common data types include:
The way date and time data is displayed can vary depending on the database system, operating system, and user preferences. It's crucial to control the display format for:
Many database systems provide functions or settings to control the display format of date and time values. Here's an example using SQL (Structured Query Language), which is commonly used with relational databases like MySQL, PostgreSQL, and SQL Server:
Function/Keyword | Description | Example |
---|---|---|
DATE_FORMAT() | This function allows you to format date and time values according to a specified format string. |
Output: The |
STRFTIME() (SQLite) | In SQLite, STRFTIME() is used for formatting date and time values. |
Output: The current date and time will be displayed in the format |
Format Masks | Format masks are strings that specify the desired output format. Common format masks include: |
Consider a database table called orders
with a order_date
column (data type: DateTime
). To display the order date in the format dd-mm-yyyy
, you would use the DATE_FORMAT()
function (or equivalent in your database system) as shown in the example above.