<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>无影的博客 &#187; 技术开发</title>
	<atom:link href="http://www.d5s.cn/archives/category/develop/feed" rel="self" type="application/rss+xml" />
	<link>http://www.d5s.cn</link>
	<description>我喜欢忽悠，她喜欢被忽悠。</description>
	<lastBuildDate>Wed, 16 Nov 2011 15:35:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Chrome 插件：新版gmail 去广告，调整textarea高度</title>
		<link>http://www.d5s.cn/archives/479</link>
		<comments>http://www.d5s.cn/archives/479#comments</comments>
		<pubDate>Wed, 16 Nov 2011 15:35:09 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[交互设计]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=479</guid>
		<description><![CDATA[textarea高度不合适，你可以自己修改。（注册一个userstyles账户，然后自定义你自己的样式。） http://userstyles.org/styles/56435/resize-gmail-textarea?r=1321457269 其实这个也支持其他浏览器。 Chrome直接点击这里安装：http://userstyles.org/styles/userjs/56435/resize%20gmail%20textarea.user.js?]]></description>
			<content:encoded><![CDATA[<p>textarea高度不合适，你可以自己修改。（注册一个userstyles账户，然后自定义你自己的样式。）</p>
<p><a href="http://userstyles.org/styles/56435/resize-gmail-textarea?r=1321457269" target="_blank">http://userstyles.org/styles/56435/resize-gmail-textarea?r=1321457269</a><br />
其实这个也支持其他浏览器。</p>
<p>Chrome直接点击这里安装：<a href="http://userstyles.org/styles/userjs/56435/resize%20gmail%20textarea.user.js?">http://userstyles.org/styles/userjs/56435/resize%20gmail%20textarea.user.js?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/479/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to fix cross-domain with local mode in firefox?</title>
		<link>http://www.d5s.cn/archives/466</link>
		<comments>http://www.d5s.cn/archives/466#comments</comments>
		<pubDate>Fri, 11 Nov 2011 06:53:55 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[交互设计]]></category>
		<category><![CDATA[程序]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=466</guid>
		<description><![CDATA[How to fix cross-domain with local mode in firefox? Demo Link: http://www.d5s.cn/example/js/cross-domain.html 1. PHP Code &#60;?php header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); header('Access-Control-Max-Age: 1000'); if(array_key_exists('HTTP_ACCESS_CONTROL_REQUEST_HEADERS', $_SERVER)) { header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']); } else { header('Access-Control-Allow-Headers: *'); } if("OPTIONS" == $_SERVER['REQUEST_METHOD']) { &#8230; <a href="http://www.d5s.cn/archives/466">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h1>How to fix cross-domain with local mode in firefox?</h1>
<p>Demo Link: <a href="http://www.d5s.cn/example/js/cross-domain.html" target="_blank">http://www.d5s.cn/example/js/cross-domain.html</a></p>
<h2>1. PHP Code</h2>
<pre>&lt;?php
  header('Access-Control-Allow-Origin: *');
  header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
  header('Access-Control-Max-Age: 1000');
  if(array_key_exists('HTTP_ACCESS_CONTROL_REQUEST_HEADERS', $_SERVER)) {
    header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
  } else {
    header('Access-Control-Allow-Headers: *');
  }
  if("OPTIONS" == $_SERVER['REQUEST_METHOD']) {
    exit();
  }
?&gt;</pre>
<h2>2. Apache Config</h2>
<pre>&lt;VirtualHost *:80&gt;
  DocumentRoot "/Users/owen/web/www.skyway.com"
  ServerName www.skyway.com
  Header always set Access-Control-Allow-Origin "*"
  Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS"
  RewriteEngine On
  RewriteCond %{REQUEST_METHOD} OPTIONS
  RewriteRule .* / [R=200,L]
&lt;/VirtualHost&gt;</pre>
<h2>3. about:config</h2>
<p>Execute this code before call the request.open() each times.</p>
<pre>  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserRead");</pre>
<pre>  signed.applets.codebase_principal_support = true</pre>
<h1>Server Code</h1>
<h2>1. Source Code: gp.php (Need change firefox setting)</h2>
<pre>&lt;?php
  if($_GET['a']){
    echo 'Get: '.$_GET['a'];
  }
  if($_POST['a']){
    echo 'Post: '.$_POST['a'];
  }
?&gt;</pre>
<h2>2. Source Code: gpo.php (√ Nothing change in client side and both working in Firefox and Chrome)</h2>
<pre>&lt;?php
  header('Access-Control-Allow-Origin: *');
  header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
  header('Access-Control-Max-Age: 1000');
  if(array_key_exists('HTTP_ACCESS_CONTROL_REQUEST_HEADERS', $_SERVER)) {
    header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
  } else {
    header('Access-Control-Allow-Headers: *');
  }
  if("OPTIONS" == $_SERVER['REQUEST_METHOD']) {
    exit();
  }
  if($_GET['a']){
    echo 'Get: '.$_GET['a'];
  }
  if($_POST['a']){
    echo 'Post: '.$_POST['a'];
  }
?&gt;</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/466/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>灯塔</title>
		<link>http://www.d5s.cn/archives/453</link>
		<comments>http://www.d5s.cn/archives/453#comments</comments>
		<pubDate>Thu, 28 Jul 2011 09:07:47 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[生活工作]]></category>
		<category><![CDATA[程序]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=453</guid>
		<description><![CDATA[出差2周，2个周末，4天，1次Great Mall,， 3次Gilroy，疯狂的购物，一次都没有出去旅游过。 主要是司机都呆的太久了，哪里都不想去，真怀念上次一起出差的刘大招，和她一起什么都不用想，只需要陪玩儿就行了。 这是第3个周末，不能再去购物了，该出去转转了。这周终于计划出去了，去看一个传说中的灯塔。 去的时候，穿过三藩，翻过高山，山路崎岖，但感觉很好。 一路上，从夏天到冬天，从晴天到大雾，穿梭于各种气候环境中。 妈妈过冬天，女儿过夏天。 这个时候，其实已经到了终点&#8211;灯塔。但是雾太大，没有拍全景照片，看这个花就知道这里有多冷，上面仿佛有一层霜。 可惜雾太大，否则坐在长椅上，看海，应该感觉很好。 路边的小花，摇曳的开着。 与山融为一体的大树。 母子两个，仿佛是家鹿一样，根本没有害怕人的概念，没有感受过，就真不知道什么是人与自然的和谐。 其实在翻山的时候，也遇到了两只鹿过马路，所有的车一致让行。 房子总是依树而建，感觉很好。 再来一个远景。 不知道这是哪个小动物的头骨。 这种地貌的岩石，不应该出现在这里。 一组怪石。 下面的大海，暗礁林立，到处都是漩涡，海浪声音不断，适合听着海浪睡觉。 其实这才是今天此行的主角&#8211;Light House。 主角中的明星&#8211;灯塔。 没有赶上好时机，一直都是大雾，或许晴天的时候，景色会好很多。]]></description>
			<content:encoded><![CDATA[<p>出差2周，2个周末，4天，1次Great Mall,， 3次Gilroy，疯狂的购物，一次都没有出去旅游过。</p>
<p>主要是司机都呆的太久了，哪里都不想去，真怀念上次一起出差的<a href="http://blog.liuj.in/" target="_blank">刘大招</a>，和她一起什么都不用想，只需要陪玩儿就行了。</p>
<p>这是第3个周末，不能再去购物了，该出去转转了。这周终于计划出去了，去看一个传说中的灯塔。</p>
<p><img src="http://farm7.static.flickr.com/6029/5984151094_9caed4fe45_z.jpg" alt="" /></p>
<p>去的时候，穿过三藩，翻过高山，山路崎岖，但感觉很好。</p>
<p>一路上，从夏天到冬天，从晴天到大雾，穿梭于各种气候环境中。</p>
<p><img src="http://farm7.static.flickr.com/6029/5984151350_027b5a69fc_z.jpg" alt="" /></p>
<p>妈妈过冬天，女儿过夏天。</p>
<p><img src="http://farm7.static.flickr.com/6125/5983590137_2cd8c64acb_z.jpg" alt="" /></p>
<p>这个时候，其实已经到了终点&#8211;灯塔。但是雾太大，没有拍全景照片，看这个花就知道这里有多冷，上面仿佛有一层霜。</p>
<p><img src="http://farm7.static.flickr.com/6138/5983590355_b5064fc5f9_z.jpg" alt="" /></p>
<p>可惜雾太大，否则坐在长椅上，看海，应该感觉很好。</p>
<p><img src="http://farm7.static.flickr.com/6015/5984152196_e662bfe50b_z.jpg" alt="" /></p>
<p>路边的小花，摇曳的开着。</p>
<p><img src="http://farm7.static.flickr.com/6020/5984152514_e9771ffc61_z.jpg" alt="" /></p>
<p>与山融为一体的大树。</p>
<p><img src="http://farm7.static.flickr.com/6146/5984152826_fff0d7b2ef_z.jpg" alt="" /></p>
<p>母子两个，仿佛是家鹿一样，根本没有害怕人的概念，没有感受过，就真不知道什么是人与自然的和谐。<br />
其实在翻山的时候，也遇到了两只鹿过马路，所有的车一致让行。</p>
<p><img src="http://farm7.static.flickr.com/6148/5983591423_89b66ff798_z.jpg" alt="" /></p>
<p>房子总是依树而建，感觉很好。</p>
<p><img src="http://farm7.static.flickr.com/6136/5984153382_9b27d77d04_z.jpg" alt="" /></p>
<p>再来一个远景。</p>
<p><img src="http://farm7.static.flickr.com/6138/5983591951_5628f6f8e6_z.jpg" alt="" /></p>
<p>不知道这是哪个小动物的头骨。</p>
<p><img src="http://farm7.static.flickr.com/6024/5983592231_669738308b_z.jpg" alt="" /></p>
<p>这种地貌的岩石，不应该出现在这里。</p>
<p><img src="http://farm7.static.flickr.com/6026/5983592555_3f74b94851_z.jpg" alt="" /></p>
<p>一组怪石。</p>
<p><img src="http://farm7.static.flickr.com/6122/5983592827_3ea7f021b3_z.jpg" alt="" /></p>
<p>下面的大海，暗礁林立，到处都是漩涡，海浪声音不断，适合听着海浪睡觉。</p>
<p><img src="http://farm7.static.flickr.com/6007/5984154878_30482e8c27_z.jpg" alt="" /></p>
<p>其实这才是今天此行的主角&#8211;Light House。</p>
<p><img src="http://farm7.static.flickr.com/6149/5983593301_27a5c38773_z.jpg" alt="" /></p>
<p>主角中的明星&#8211;灯塔。</p>
<p>没有赶上好时机，一直都是大雾，或许晴天的时候，景色会好很多。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/453/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>用vi删除某一列</title>
		<link>http://www.d5s.cn/archives/449</link>
		<comments>http://www.d5s.cn/archives/449#comments</comments>
		<pubDate>Fri, 20 May 2011 14:25:23 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[服务器&PC]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=449</guid>
		<description><![CDATA[vi   中如何一次删除多列? 如: 123aaaaa !@#aaaaa ABCaaaaa +-/aaaaa 在   vi   中如何一次删除前   3   列呢?最简单的方法：1. 先ctrl-v进行visual   block模式 2. 移动光标，按列选择你要删除的列 3. 然后按x命令删除。 具体讲，光标先移动到第一行，第一列，然后按ctrl   +   v， 然后把光标移动到第三行，第三列，再按x键。 就可以删除前三行前三列。 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Ctrl+V, G 之后再右移光标选种几列进行删除x 如果不用G的话，可以手动自己移动光标进行选择，最后删除 当然如果用cut和awk也是可以实现的 比如删除第10列， 文件有100列 cut -d ” ” -f 1-9,11-100 urfile &#8230; <a href="http://www.d5s.cn/archives/449">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>vi   中如何一次删除多列? <br style="line-height: normal;" /><br style="line-height: normal;" />如: <br style="line-height: normal;" /><br style="line-height: normal;" />123aaaaa <br style="line-height: normal;" />!@#aaaaa <br style="line-height: normal;" />ABCaaaaa <br style="line-height: normal;" />+-/aaaaa <br style="line-height: normal;" /><br style="line-height: normal;" /><br style="line-height: normal;" />在   vi   中如何一次删除前   3   列呢?<br style="line-height: normal;" /><br style="line-height: normal;" />最简单的方法：<br style="line-height: normal;" />1. 先ctrl-v进行visual   block模式</p>
<p>2. 移动光标，按列选择你要删除的列</p>
<p>3. 然后按x命令删除。</p>
<p>具体讲，光标先移动到第一行，第一列，然后按ctrl   +   v，</p>
<p>然后把光标移动到第三行，第三列，再按x键。</p>
<p>就可以删除前三行前三列。</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Ctrl+V, G 之后再右移光标选种几列进行删除x<br />
如果不用G的话，可以手动自己移动光标进行选择，最后删除</p>
<p>当然如果用cut和awk也是可以实现的</p>
<p>比如删除第10列，</p>
<p>文件有100列</p>
<p>cut -d ” ” -f 1-9,11-100 urfile</p>
<p>or:</p>
<p>awk &#8216;{$10=”",print}&#8217; urfile</p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/449/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Selenium 测试笔记</title>
		<link>http://www.d5s.cn/archives/445</link>
		<comments>http://www.d5s.cn/archives/445#comments</comments>
		<pubDate>Thu, 21 Apr 2011 03:13:47 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[交互设计]]></category>
		<category><![CDATA[程序]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=445</guid>
		<description><![CDATA[好久没做Selenium的测试了，命令几乎都忘记了。 做个笔记，方便下次查询。 Firefox的另一个插件： Firefinder很好用，比Selenium自带的找DOM工具要方便，尤其是像用GI这种 JS Framework 开发出来的产品。 1. 根据文字内容来确定结点，去除文字中的空格。 //td[@jsxtype="text"]/div[contains(normalize-space(text()), 'app3')] 2. 查找父级元素 //div[@class="abc"]/.. 3. focus, mouseOver, click连用，某些时候，点击事件无效的时候可以试试 focus &#124; //span[@label="applications"] &#124; mouseOver &#124; //span[@label="applications"] &#124; click &#124; //span[@label="applications"] &#124; 4. Selenium 去前后空格后验证 （正则表达式） //a[contains(text(),"name")]/following::td[1][normalize-space(text())='Text Box'] 5. Selenium 用带正则表达式的 replace 来 替换 字符 store &#8230; <a href="http://www.d5s.cn/archives/445">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>好久没做Selenium的测试了，命令几乎都忘记了。</p>
<p>做个笔记，方便下次查询。</p>
<p>Firefox的另一个插件： Firefinder很好用，比Selenium自带的找DOM工具要方便，尤其是像用GI这种 JS Framework 开发出来的产品。</p>
<p>1. 根据文字内容来确定结点，去除文字中的空格。<br />
//td[@jsxtype="text"]/div[contains(normalize-space(text()), 'app3')]</p>
<p>2. 查找父级元素<br />
//div[@class="abc"]/..</p>
<p>3. focus, mouseOver, click连用，某些时候，点击事件无效的时候可以试试</p>
<p>focus | //span[@label="applications"] |<br />
mouseOver | //span[@label="applications"] |<br />
click | //span[@label="applications"] |</p>
<p>4. Selenium 去前后空格后验证 （正则表达式）<br />
//a[contains(text(),"name")]/following::td[1][normalize-space(text())='Text Box']</p>
<p>5. Selenium 用带正则表达式的 replace 来 替换 字符<br />
store | https://xx.com//g.php?t=xxx | url<br />
storeEval | “${url}”.replace(/&amp;/g,”*”) | urlResult<br />
echo | ${urlResult} |</p>
<p>6. waitForXXX，不好使的时候，就先Pause暂停一段时间。</p>
<p>7. type 不好使的时候，试试命令组合 focus, type, fireEvent(blur)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/445/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>windows 下的 svn up</title>
		<link>http://www.d5s.cn/archives/442</link>
		<comments>http://www.d5s.cn/archives/442#comments</comments>
		<pubDate>Mon, 11 Apr 2011 15:29:39 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[服务器&PC]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=442</guid>
		<description><![CDATA[使用TortoiseSVN 新建svnup.bat文件，内容如下： “C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe” /command:update /path:”C:\xampp\htdocs\abc\” /closeonend:1 参数说明参考这里：http://tortoisesvn.net/docs/release/TortoiseSVN_zh_CN/tsvn-automation.html 使用VisualSVN 新建svnup.bat文件，内容如下： “C:\Program Files\VisualSVN Server\bin\svn.exe” update “C:\xampp\htdocs\abc” 然后可以把svnup.bat文件加入计划任务，每隔5分钟执行一次，就可以自动更新了。]]></description>
			<content:encoded><![CDATA[<p><strong>使用TortoiseSVN</strong></p>
<p>新建svnup.bat文件，内容如下：</p>
<p>“C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe” /command:update /path:”C:\xampp\htdocs\abc\” /closeonend:1</p>
<p>参数说明参考这里：<a href="http://tortoisesvn.net/docs/release/TortoiseSVN_zh_CN/tsvn-automation.html" target="_blank">http://tortoisesvn.net/docs/release/TortoiseSVN_zh_CN/tsvn-automation.html</a></p>
<p><strong>使用VisualSVN</strong></p>
<p>新建svnup.bat文件，内容如下：</p>
<p>“C:\Program Files\VisualSVN Server\bin\svn.exe” update “C:\xampp\htdocs\abc”</p>
<p>然后可以把svnup.bat文件加入计划任务，每隔5分钟执行一次，就可以自动更新了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/442/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GWT VS JQUERY VS GI</title>
		<link>http://www.d5s.cn/archives/440</link>
		<comments>http://www.d5s.cn/archives/440#comments</comments>
		<pubDate>Fri, 18 Mar 2011 17:05:23 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[交互设计]]></category>
		<category><![CDATA[GI]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[JQUERY]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=440</guid>
		<description><![CDATA[http://www.slideshare.net/owenpengtao/java-scriptmvc 对GWT, JavaScriptMVC(jquery), GI(Tibco&#8217;s product) 做的一个比较，有需要的朋友，可以看看。 jQuery 只是对DOM操作和事件做了更友好的封装，本身并不包括文件组织结构管理、测试、文档生成等功能。 JavaScriptMVC 基于jQuery，并集成了其他的一些JS组件，更有利于开发大型的JS项目。 GWT相当于是用Java语言来写JS，这是另一种开发大型JS项目的解决方案。 jQuery 仅仅适合Web Site，如果做其他大型JS项目，还要借助于其他JavaScript框架。]]></description>
			<content:encoded><![CDATA[<p><a title="GWT VS JQUERY VS GI" href="http://www.slideshare.net/owenpengtao/java-scriptmvc" target="_blank">http://www.slideshare.net/owenpengtao/java-scriptmvc</a></p>
<p>对GWT, JavaScriptMVC(jquery), GI(Tibco&#8217;s product) 做的一个比较，有需要的朋友，可以看看。</p>
<p>jQuery 只是对DOM操作和事件做了更友好的封装，本身并不包括文件组织结构管理、测试、文档生成等功能。</p>
<p>JavaScriptMVC 基于jQuery，并集成了其他的一些JS组件，更有利于开发大型的JS项目。</p>
<p>GWT相当于是用Java语言来写JS，这是另一种开发大型JS项目的解决方案。</p>
<p>jQuery 仅仅适合Web Site，如果做其他大型JS项目，还要借助于其他JavaScript框架。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/440/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MAC下，通过修改路由，只让国外的网站走VPN</title>
		<link>http://www.d5s.cn/archives/437</link>
		<comments>http://www.d5s.cn/archives/437#comments</comments>
		<pubDate>Sat, 12 Mar 2011 16:33:42 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[服务器&PC]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=437</guid>
		<description><![CDATA[骂娘的话就不说了，某些人，某些部门被骂过无数次了。 本来我是很听话的，你不让我上Twitter, Facebook, Youtube 之类的网站，我忍了，不让我用Google doc，我也忍了。现在竟然还开始搞Gmail，我就受不了了，动了我的底线。 VPN 枪在手，我跟你走。 使用VPN，有一个问题，一但连上VPN，你的所有流量都回走VPN，容易消耗很多不必要的流量。 感谢Chnroutes给了我们光明：http://code.google.com/p/chnroutes/wiki/Usage 虽然这个Wiki里面写了很多，其实MAC的设置很简单，不过我还是弄了半天才明白。 如果你是使用MAC，一切将变得简单，只需要使用系统默认的VPN网络设置就行。 pptp 1.下载 chnroutes_pptp_mac 2.从终端进入下载目录, 执行python chnroutes_pptp_mac, 执行完毕之后同一目录下将生成两个新文件&#8217;ip-up&#8217;和&#8217;ip-down&#8217; 3.把这两个文件copy到 /etc/ppp 目录, 并使用 sudo chmod a+x ip-up ip-down命令把它们设置为可执行 设置完毕。 检验一下： 1.进入终端，执行netstat -nr，看看输出的路由列表 2.连上VPN，再执行netstat -nr, 和上次的输出内容不同了。 或者分别进入 http://www.cz88.net/ 和 http://whatismyipaddress.com/ 这两个网站，将会看到两个不同的IP地址。]]></description>
			<content:encoded><![CDATA[<p>骂娘的话就不说了，某些人，某些部门被骂过无数次了。</p>
<p>本来我是很听话的，你不让我上Twitter, Facebook, Youtube 之类的网站，我忍了，不让我用Google doc，我也忍了。现在竟然还开始搞Gmail，我就受不了了，动了我的底线。<br />
VPN 枪在手，我跟你走。</p>
<p>使用VPN，有一个问题，一但连上VPN，你的所有流量都回走VPN，容易消耗很多不必要的流量。<br />
感谢Chnroutes给了我们光明：<a href="http://code.google.com/p/chnroutes/wiki/Usage" target="_blank">http://code.google.com/p/chnroutes/wiki/Usage</a></p>
<p>虽然这个Wiki里面写了很多，其实MAC的设置很简单，不过我还是弄了半天才明白。<br />
如果你是使用MAC，一切将变得简单，只需要使用系统默认的VPN网络设置就行。</p>
<p>pptp<br />
1.下载 <a href="http://code.google.com/p/chnroutes/downloads/detail?name=chnroutes_pptp_mac&#038;can=2&#038;q=" target="_blank">chnroutes_pptp_mac</a><br />
2.从终端进入下载目录, 执行python chnroutes_pptp_mac, 执行完毕之后同一目录下将生成两个新文件&#8217;ip-up&#8217;和&#8217;ip-down&#8217;<br />
3.把这两个文件copy到 /etc/ppp 目录, 并使用 sudo chmod a+x ip-up ip-down命令把它们设置为可执行<br />
设置完毕。</p>
<p>检验一下：</p>
<p>1.进入终端，执行netstat -nr，看看输出的路由列表</p>
<p>2.连上VPN，再执行netstat -nr, 和上次的输出内容不同了。</p>
<p>或者分别进入 <a style="color: #0000cc;" rel="nofollow" href="http://www.cz88.net/">http://www.cz88.net/</a> 和 <a style="color: #0000cc;" rel="nofollow" href="http://whatismyipaddress.com/">http://whatismyipaddress.com/</a> 这两个网站，将会看到两个不同的IP地址。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/437/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>3天时间，被垃圾蜘蛛爬虫耗尽了10G的流量</title>
		<link>http://www.d5s.cn/archives/427</link>
		<comments>http://www.d5s.cn/archives/427#comments</comments>
		<pubDate>Sun, 06 Mar 2011 05:29:20 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[数据库]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=427</guid>
		<description><![CDATA[unknown robot (identified by empty user agent string) 10.25 g 从3月1日到3日，仅仅3的时间。 联系主机托管方HomeZZ.com 的管理员，经过查找后，发现主机上其他账户正常，不是主机问题。 查看日志后，发现有来自 208.101.54.6-static.reverse.softlayer.com (208.101.54.6) 的访客，消耗流量最多10g左右，于是禁用ip，目前站点流量正常。 在robots.txt里面也禁禁止了很多垃圾机器人来抓取本站。 这次被攻击，HomeZZ的管理员又给了2G的流量，十分感谢，推荐其他朋友也来这里购买虚拟主机。 这里放出几个邀请码，有需要的自取： https://homezz.com/account/reg.php?c=NO1HA17K https://homezz.com/account/reg.php?c=F1RU0FB2 https://homezz.com/account/reg.php?c=HE050ICN]]></description>
			<content:encoded><![CDATA[<p>unknown robot (identified by empty user agent string)	 10.25 g<br />
从3月1日到3日，仅仅3的时间。</p>
<p>联系主机托管方<a href="https://homezz.com" target="_blank">HomeZZ.com</a> 的管理员，经过查找后，发现主机上其他账户正常，不是主机问题。<br />
查看日志后，发现有来自 208.101.54.6-static.reverse.softlayer.com (208.101.54.6) 的访客，消耗流量最多10g左右，于是禁用ip，目前站点流量正常。</p>
<p>在robots.txt里面也禁禁止了很多垃圾机器人来抓取本站。</p>
<p>这次被攻击，HomeZZ的管理员又给了2G的流量，十分感谢，推荐其他朋友也来这里购买虚拟主机。<br />
这里放出几个邀请码，有需要的自取：</p>
<p><a href="https://homezz.com/account/reg.php?c=NO1HA17K" target="_blank">https://homezz.com/account/reg.php?c=NO1HA17K</a></p>
<p><a href="https://homezz.com/account/reg.php?c=F1RU0FB2" target="_blank">https://homezz.com/account/reg.php?c=F1RU0FB2</a></p>
<p><a href="https://homezz.com/account/reg.php?c=HE050ICN" target="_blank">https://homezz.com/account/reg.php?c=HE050ICN</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/427/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>mysql 中 时间和日期函数</title>
		<link>http://www.d5s.cn/archives/422</link>
		<comments>http://www.d5s.cn/archives/422#comments</comments>
		<pubDate>Sat, 12 Feb 2011 12:28:29 +0000</pubDate>
		<dc:creator>owen</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.d5s.cn/?p=422</guid>
		<description><![CDATA[转自：http://www.cnblogs.com/redfox241/archive/2009/07/23/1529092.html 一、MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间（date + time）函数：now() mysql&#62; select now(); +&#8211;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+ &#124; now() &#124; +&#8211;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+ &#124; 2008-08-08 22:20:46 &#124; +&#8211;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+ 除了 now() 函数能获得当前的日期时间外，MySQL 中还有下面的函数： current_timestamp() ,current_timestamp ,localtime() ,localtime ,localtimestamp &#8211; (v4.0.6) ,localtimestamp() &#8211; (v4.0.6) 这些日期时间函数，都等同于 now()。鉴于 now() 函数简短易记，建议总是使用 now() 来替代上面列出的函数。 1.2 获得当前日期+时间（date + time）函数：sysdate() sysdate() 日期时间函数跟 now() 类似，不同之处在于：now() 在执行开始时值就得到了， sysdate() 在函数执行时动态得到值。看下面的例子就明白了： mysql&#62; select now(), sleep(3), now(); +&#8211;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+ &#8230; <a href="http://www.d5s.cn/archives/422">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>转自：http://www.cnblogs.com/redfox241/archive/2009/07/23/1529092.html</p>
<p><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">一、MySQL 获得当前日期时间 函数</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1.1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 获得当前日期</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">时间（date </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> time）函数：now()</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> now();</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> now() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">20</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">46</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
除了 now() 函数能获得当前的日期时间外，MySQL 中还有下面的函数：</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">current_timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">()<br />
,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">current_timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
,localtime()<br />
,localtime<br />
,localtimestamp </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> (v4.0.6)</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,localtimestamp() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> (v4.0.6)</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
这些日期时间函数，都等同于 now()。鉴于 now() 函数简短易记，建议总是使用 now() 来替代上面列出的函数。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1.2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 获得当前日期</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">时间（date </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> time）函数：sysdate()</p>
<p>sysdate() 日期时间函数跟 now() 类似，不同之处在于：now() 在执行开始时值就得到了， sysdate() 在函数执行时动态得到值。看下面的例子就明白了：</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> now(), sleep(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">), now();</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> now() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> sleep(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> now() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">28</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">21</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">0</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">28</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">21</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> sysdate(), sleep(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">), sysdate();</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> sysdate() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> sleep(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> sysdate() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">28</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">41</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">0</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">28</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">44</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
可以看到，虽然中途 sleep </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 秒，但 now() 函数两次的时间值是相同的； sysdate() 函数两次得到的时间值相差 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 秒。MySQL Manual 中是这样描述 sysdate() 的：</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">Return</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> the time at which the </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">function</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> executes。</p>
<p>sysdate() 日期时间函数，一般情况下很少用到。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. 获得当前日期（date）函数：curdate()</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> curdate();</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> curdate() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
其中，下面的两个日期函数等同于 curdate()：</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">current_date</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">()<br />
,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">current_date</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"></p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. 获得当前时间（time）函数：curtime()</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> curtime();</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> curtime() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">41</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
其中，下面的两个时间函数等同于 curtime()：</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">current_time</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">()<br />
,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">current_time</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"></p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">4</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. 获得当前 UTC 日期时间函数：utc_date(), utc_time(), utc_timestamp()</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> utc_timestamp(), utc_date(), utc_time(), now()</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> utc_timestamp() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> utc_date() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> utc_time() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> now() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">14</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">47</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">11</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">14</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">47</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">11</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">47</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">11</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
因为我国位于东八时区，所以本地时间 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> UTC 时间 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">8</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 小时。UTC 时间在业务涉及多个国家和地区的时候，非常有用。<br />
二、MySQL 日期时间 Extract（选取） 函数。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. 选取日期时间的各个部分：日期、时间、年、季度、月、日、小时、分钟、秒、微秒</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">set</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-09-10 07:15:30.123456</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">;</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-09-10</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> time(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 07:15:30.123456</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">year</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> quarter(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">month</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 9</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> week(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 36</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 10</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> hour(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 7</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> minute(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 15</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> second(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> microsecond(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 123456</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL Extract() 函数，可以上面实现类似的功能：</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">set</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-09-10 07:15:30.123456</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">;</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">year</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(quarter </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">month</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 9</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(week </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 36</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 10</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(hour </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 7</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(minute </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 15</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(second </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(microsecond </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 123456</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(year_month </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 200809</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(day_hour </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 1007</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(day_minute </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 100715</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(day_second </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 10071530</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(day_microsecond </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 10071530123456</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(hour_minute </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 715</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(hour_second </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 71530</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(hour_microsecond </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 71530123456</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(minute_second </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 1530</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(minute_microsecond </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 1530123456</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> extract(second_microsecond </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">from</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 30123456</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL Extract() 函数除了没有date(),time() 的功能外，其他功能一应具全。并且还具有选取‘day_microsecond’ 等功能。注意这里不是只选取 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 和 microsecond，而是从日期的 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 部分一直选取到 microsecond 部分。够强悍的吧！</p>
<p>MySQL Extract() 函数唯一不好的地方在于：你需要多敲几次键盘。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL dayof… 函数：dayofweek(), dayofmonth(), dayofyear()</p>
<p>分别返回日期参数，在一周、一月、一年中的位置。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">set</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">;</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> dayofweek(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 6</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> dayofmonth(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 8</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> dayofyear(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 221</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
日期 ‘</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">′ 是一周中的第 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">6</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 天（</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Sunday, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Monday, …, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">7</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Saturday）；一月中的第 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">8</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 天；一年中的第 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">221</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 天。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">4</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL week… 函数：week(), weekofyear(), dayofweek(), weekday(), yearweek()</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">set</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">;</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> week(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 31</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> week(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 32</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> weekofyear(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 32</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> dayofweek(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 6</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> weekday(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 4</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> yearweek(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 200831</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL week() 函数，可以有两个参数，具体可看手册。 weekofyear() 和 week() 一样，都是计算“某天”是位于一年中的第几周。 weekofyear(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) 等价于 week(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)。</p>
<p>MySQL weekday() 函数和 dayofweek() 类似，都是返回“某天”在一周中的位置。不同点在于参考的标准， weekday：(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">0</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Monday, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Tuesday, …, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">6</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Sunday)； dayofweek：（</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Sunday, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Monday, …, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">7</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Saturday）</p>
<p>MySQL yearweek() 函数，返回 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">year</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> week 位置(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">31</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">5</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL 返回星期和月份名称函数：dayname(), monthname()</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">set</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">;</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> dayname(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> Friday</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> monthname(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> August</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
思考，如何返回中文的名称呢？</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">6</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL last_day() 函数：返回月份中的最后一天。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> last_day(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-02-01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-02-29</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> last_day(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-31</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL last_day() 函数非常有用，比如我想得到当前月份中有多少天，可以这样来计算：</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> now(), </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(last_day(now())) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">as</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> days;</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> now() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> days </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">09</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">11</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">45</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">45</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">31</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
三、MySQL 日期时间计算函数</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL 为日期增加一个时间间隔：date_add()</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">set</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> now();</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> add 1 day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> hour); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> add 1 hour</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> minute); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> <img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/dot.gif" alt="" /></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> second);<br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> microsecond);<br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> week);<br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">month</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">);<br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> quarter);<br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">year</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">);</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> sub 1 day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL adddate(), addtime()函数，可以用 date_add() 来替代。下面是 date_add() 实现 addtime() 功能示例：</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">set</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">=</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-09 12:12:33</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">;</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">01:15:30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> hour_second);</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">01:15:30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> hour_second) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">09</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">13</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">28</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">03</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">1 01:15:30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> day_second);</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">1 01:15:30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> day_second) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">10</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">13</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">28</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">03</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
date_add() 函数，分别为 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008000;">@dt</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> 增加了“1小时 15分 30秒” 和 “1天 1小时 15分 30秒”。建议：总是使用 date_add() 日期时间函数来替代 adddate(), addtime()。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL 为日期减去一个时间间隔：date_sub()</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_sub(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">1998-01-01 00:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">1 1:1:1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> day_second);</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_sub(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">1998-01-01 00:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">1 1:1:1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> day_second) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1997</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">12</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">58</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">59</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL date_sub() 日期时间函数 和 date_add() 用法一致，不再赘述。另外，MySQL 中还有两个函数 subdate(), subtime()，建议，用 date_sub() 来替代。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL 另类日期函数：period_add(P,N), period_diff(P1,P2)</p>
<p>函数参数“P” 的格式为“YYYYMM” 或者 “YYMM”，第二个参数“N” 表示增加或减去 N </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">month</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">（月）。</p>
<p>MySQL period_add(P,N)：日期加</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">/</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">减去N月。</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> period_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">200808</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">), period_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">20080808</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> period_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">200808</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> period_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">20080808</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">200810</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">20080806</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL period_diff(P1,P2)：日期 P1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">P2，返回 N 个月。</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> period_diff(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">200808</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">200801</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">);</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> period_diff(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">200808</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">200801</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">7</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
在 MySQL 中，这两个日期函数，一般情况下很少用到。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">4</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL 日期、时间相减函数：</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">datediff</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(date1,date2), timediff(time1,time2)</p>
<p>MySQL </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">datediff</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(date1,date2)：两个日期相减 date1 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date2，返回天数。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">datediff</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 7</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">datediff</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> -7</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL timediff(time1,time2)：两个日期相减 time1 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> time2，返回 time 差值。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> timediff(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 08:08:08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 00:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 08:08:08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> timediff(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">08:08:08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">00:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 08:08:08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
注意：timediff(time1,time2) 函数的两个参数类型必须相同。<br />
四、MySQL 日期转换函数、时间转换函数</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL （时间、秒）转换函数：time_to_sec(time), sec_to_time(seconds)</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> time_to_sec(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">01:00:05</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 3605</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> sec_to_time(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3605</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;01:00:05&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL （日期、天数）转换函数：to_days(date), from_days(days)</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> to_days(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">0000-00-00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 0</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> to_days(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 733627</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> from_days(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">0</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;0000-00-00&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> from_days(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">733627</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;2008-08-08&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">Str</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">to</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Date （字符串转换为日期）函数：str_to_date(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">str</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, format)</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> str_to_date(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">08/09/2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%m/%d/%Y</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-09</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> str_to_date(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">08/09/08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> , </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%m/%d/%y</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-09</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> str_to_date(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">08.09.2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%m.%d.%Y</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-09</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> str_to_date(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">08:09:30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%h:%i:%s</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 08:09:30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> str_to_date(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">08.09.2008 08:09:30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%m.%d.%Y %h:%i:%s</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-09 08:09:30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
可以看到，str_to_date(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">str</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,format) 转换函数，可以把一些杂乱无章的字符串转换为日期格式。另外，它也可以转换为时间。“format” 可以参看 MySQL 手册。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">4</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL Date</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">/</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">Time </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">to</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">Str</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">（日期</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">/</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">时间转换为字符串）函数：date_format(date,format), time_format(time,format)</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 22:23:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%W %M %Y</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">);</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 22:23:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%W %M %Y</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> Friday August </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 22:23:01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%Y%m%d%H%i%s</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">);</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 22:23:01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%Y%m%d%H%i%s</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">20080808222301</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> time_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">22:23:01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%H.%i.%s</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">);</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> time_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">22:23:01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%H.%i.%s</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22.23</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">.</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL 日期、时间转换函数：date_format(date,format), time_format(time,format) 能够把一个日期</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">/</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">时间转换成各种各样的字符串格式。它是 str_to_date(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">str</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,format) 函数的 一个逆转换。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">5</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL 获得国家地区时间格式函数：get_format()</p>
<p>MySQL get_format() 语法：</p>
<p>get_format(date</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">time</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">datetime</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">eur</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">usa</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">jis</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">iso</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">internal</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"></p>
<p>MySQL get_format() 用法的全部示例：</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(date,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">usa</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)          ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%m.%d.%Y&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(date,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">jis</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)          ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%Y-%m-%d&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(date,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">iso</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)          ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%Y-%m-%d&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(date,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">eur</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)          ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%d.%m.%Y&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(date,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">internal</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)     ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%Y%m%d&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">datetime</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">usa</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)      ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%Y-%m-%d %H.%i.%s&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">datetime</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">jis</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)      ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%Y-%m-%d %H:%i:%s&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">datetime</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">iso</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)      ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%Y-%m-%d %H:%i:%s&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">datetime</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">eur</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)      ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%Y-%m-%d %H.%i.%s&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">datetime</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">internal</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">) ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%Y%m%d%H%i%s&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(time,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">usa</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)          ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%h:%i:%s %p&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(time,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">jis</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)          ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%H:%i:%s&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(time,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">iso</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)          ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%H:%i:%s&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(time,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">eur</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)          ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%H.%i.%s&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> get_format(time,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">internal</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">)     ; </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8216;%H%i%s&#8217;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL get_format() 函数在实际中用到机会的比较少。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">6</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL 拼凑日期、时间函数：makdedate(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">year</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,dayofyear), maketime(hour,minute,second)</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> makedate(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2001</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">31</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;2001-01-31&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> makedate(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2001</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">32</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;2001-02-01&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> maketime(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">12</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">15</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">30</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;12:15:30&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
五、MySQL 时间戳（</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">Timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">）函数</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL 获得当前时间戳函数：</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">current_timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">current_timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">()</p>
<p>mysql</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">&gt;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">current_timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">current_timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">();</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">current_timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">current_timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">() </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">09</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">23</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">24</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2008</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">09</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">23</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">22</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">:</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">24</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">|</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">2</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL （Unix 时间戳、日期）转换函数：</p>
<p>unix_timestamp(),<br />
unix_timestamp(date),<br />
from_unixtime(unix_timestamp),<br />
from_unixtime(unix_timestamp,format)</p>
<p>下面是示例：</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> unix_timestamp(); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 1218290027</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> unix_timestamp(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 1218124800</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> unix_timestamp(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 12:30:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 1218169800</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> from_unixtime(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1218290027</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;2008-08-09 21:53:47&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> from_unixtime(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1218124800</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;2008-08-08 00:00:00&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> from_unixtime(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1218169800</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;2008-08-08 12:30:00&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> from_unixtime(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1218169800</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">%Y %D %M %h:%i:%s %x</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> &#8217;2008 8th August 12:30:00 2008&#8242;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">3</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">. MySQL 时间戳（</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">）转换、增、减函数：</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(date) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> date to timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(dt,time) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> dt + time</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">timestampadd(unit,interval,datetime_expr) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;<br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">timestampdiff(unit,datetime_expr1,datetime_expr2) </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;<br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
请看示例部分：</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-08 00:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 08:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">01:01:01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-08 09:01:01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">timestamp</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 08:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">10 01:01:01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-18 09:01:01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> timestampadd(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 08:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-09 08:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 08:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-09 08:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL timestampadd() 函数类似于 date_add()。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> timestampdiff(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">year</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2002-05-01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2001-01-01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> -1</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> timestampdiff(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">day</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> ,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2002-05-01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2001-01-01</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> -485</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> timestampdiff(hour,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 12:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">,</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 00:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> -12</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">datediff</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 12:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-01 00:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 7</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
MySQL timestampdiff() 函数就比 </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">datediff</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">() 功能强多了，</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff00ff;">datediff</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">() 只能计算两个日期（date）之间相差的天数。<br />
六、MySQL 时区（timezone）转换函数</p>
<p>convert_tz(dt,from_tz,to_tz)</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> convert_tz(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 12:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">+08:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">+00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-08 04:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"><br />
时区转换也可以通过 date_add, date_sub, timestampadd 来实现。</p>
<p></span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_add(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 12:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">8</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> hour); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-08 04:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> date_sub(</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 12:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, interval </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">8</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> hour); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-08 04:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"><br />
</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #0000ff;">select</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;"> timestampadd(hour, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #808080;">-</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #800000; font-weight: bold;">8</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">, </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">2008-08-08 12:00:00</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #ff0000;">&#8216;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #000000;">); </span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;">&#8211;</span><span style="line-height: 1.5; font-size: 13px; font-family: 'Courier New'; color: #008080;"> 2008-08-08 04:00:00</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.d5s.cn/archives/422/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

