SQL Date Functions/ 数据库中日期时间函数
来源:互联网 发布:班班通软件下载 编辑:程序博客网 时间:2024/05/18 04:30
原文来自:http://www.w3schools.com/sql/sql_dates.asp
SQL Dates
The most difficult part when working with dates is to be sure that the format of the date you are trying to insert, matches the format of the date column in the database.
As long as your data contains only the date portion, your queries will work as expected. However, if a time portion is involved, it gets complicated.
Before talking about the complications of querying for dates, we will look at the most important built-in functions for working with dates.
MySQL Date Functions
The following table lists the most important built-in date functions in MySQL:
SQL Server Date Functions
The following table lists the most important built-in date functions in SQL Server:
SQL Date Data Types
MySQL comes with the following data types for storing a date or a date/time value in the database:
- DATE - format YYYY-MM-DD
- DATETIME - format: YYYY-MM-DD HH:MM:SS
- TIMESTAMP - format: YYYY-MM-DD HH:MM:SS
- YEAR - format YYYY or YY
SQL Server comes with the following data types for storing a date or a date/time value in the database:
- DATE - format YYYY-MM-DD
- DATETIME - format: YYYY-MM-DD HH:MM:SS
- SMALLDATETIME - format: YYYY-MM-DD HH:MM:SS
- TIMESTAMP - format: a unique number
Note: The date types are chosen for a column when you create a new table in your database!
For an overview of all data types available, go to our complete Data Types reference.
SQL Working with Dates
You can compare two dates easily if there is no time component involved!
Assume we have the following "Orders" table:
Now we want to select the records with an OrderDate of "2008-11-11" from the table above.
We use the following SELECT statement:
The result-set will look like this:
Now, assume that the "Orders" table looks like this (notice the time component in the "OrderDate" column):
If we use the same SELECT statement as above:
we will get no result! This is because the query is looking only for dates with no time portion.
Tip: If you want to keep your queries simple and easy to maintain, do not allow time components in your dates!
- SQL Date Functions/ 数据库中日期时间函数
- SQL数据库中日期函数
- SQL中日期/时间函数的处理
- MySQL 数据库中日期与时间函数
- php中日期时间函数date()用法总结
- 数据库中日期函数
- SQL 10 函数 3 日期时间函数 - 2 主流数据库系统中日期时间类型的表示方式
- MySQL 数据库中日期与时间函数FROM_UNIXTIME(), UNIX_TIMESTAMP()
- MySQL 数据库中日期与时间函数FROM_UNIXTIME(), UNIX_TIMESTAMP()
- pgsql数据库和PHP中日期、时间戳处理函数
- MySQL 数据库中日期与时间函数FROM_UNIXTIME(), UNIX_TIMESTAMP()
- javascript中日期函数Date详解
- JavaScript中日期和时间函数Date的简单用例
- mysql中日期函数、时间函数
- sql语句中日期时间格式化查询
- sql语句中日期时间格式化查询
- sql语句中日期时间格式化查询
- sql server中日期时间格式转换
- 理解Java机制最受欢迎的8幅图
- 正则表达式练习
- linux VLAN配置(vconfig)
- 如何统计代码数量
- Spring+ibatis动态管理数据源
- SQL Date Functions/ 数据库中日期时间函数
- cocos2d-x CCCallFunc系列函数的应用
- oracle sql 知识 积累
- 64位Windows Server 2208 R2不能运行php
- 初识CUDA
- 网站推广的方法
- Android中加入悬浮窗
- WaterColourVoiceView
- 关于网络异步缓存相关