<?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>Sybase数据库技术，数据库恢复专家 &#187; date</title>
	<atom:link href="http://www.dbainfo.net/tag/date/feed" rel="self" type="application/rss+xml" />
	<link>https://www.dbainfo.net</link>
	<description>提供Sybase ASE及Sybase SQL Anywhere数据库修复服务，电话：13811580958(微信)，QQ：289965371！We have many years of experience in recovering data from damanged Sybase devices. Contact us by Phone: +86 13811580958 Wechat: 13811580958 Email: 289965371@qq.com</description>
	<lastBuildDate>Sat, 14 Jun 2025 16:28:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>linux使用date计算某个月份的天数</title>
		<link>https://www.dbainfo.net/linux-date-count-days-of-month.htm</link>
		<comments>https://www.dbainfo.net/linux-date-count-days-of-month.htm#comments</comments>
		<pubDate>Thu, 01 Dec 2011 05:07:10 +0000</pubDate>
		<dc:creator>dbainfo</dc:creator>
				<category><![CDATA[Unix&Linux]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.dbainfo.net/?p=1289</guid>
		<description><![CDATA[本博客中aix系统可以用改变时区的方法获取前后N天的日期 Linux下使用date计算某个月份的天数： Month=2 Year=2008 nextmonth=`date -d &#34;1 month $Year-$Month-&#34;01&#34;&#34; +%Y-%m-%d` date -d &#34;-1 day $nextmonth&#34; +%d #或者将-d &#34;1 month $Year-$Month-&#34;01&#34;&#34; 和 date -d &#34;-1 day $nextmonth&#34; 写在一行命令中 Month=2 Year=2008 date -d &#34;1 month $Year-$Month-&#34;01&#34;&#34; -d &#34;-1 day&#34; +%d 使用cal 计算某个月份的天数： Month=2 Year=2008 cal $Month $Year &#124; sed -n &#39;3,$p&#39; &#124; xargs &#124; awk &#39;{print $NF}&#39; [...]]]></description>
			<content:encoded><![CDATA[<p>本博客中<a href="https://www.dbainfo.net/aix-date-change-time-zone-to-get-date.htm" target="_blank">aix系统可以用改变时区的方法获取前后N天的日期</a></p>
<p>Linux下使用date计算某个月份的天数：</p>
<pre>Month=2
Year=2008
nextmonth=`date -d &quot;1 month $Year-$Month-&quot;01&quot;&quot;  +%Y-%m-%d`
date -d &quot;-1 day $nextmonth&quot; +%d
#或者将-d &quot;1 month $Year-$Month-&quot;01&quot;&quot; 和 date -d &quot;-1 day $nextmonth&quot; 写在一行命令中
Month=2
Year=2008
date -d &quot;1 month $Year-$Month-&quot;01&quot;&quot; -d &quot;-1 day&quot; +%d
</pre>
<p>使用cal 计算某个月份的天数：<span id="more-1289"></span></p>
<pre>Month=2
Year=2008
cal $Month $Year | sed -n &#39;3,$p&#39; | xargs | awk &#39;{print $NF}&#39;
</pre>
<p>计算当月的天数：</p>
<pre>date -d &#39;1 month &#39; -d  &#39;1 days ago&#39; +%d
#或者
cal | sed -n &#39;3,$p&#39; | xargs | awk &#39;{print $NF}&#39;</pre>
<hr />
<p>由于Linux对man date -d 参数说的比较模糊,故举例如下:<br />
	# -d, --date=STRING&nbsp; display time described by STRING, not `now&#39;</p>
<p>参数-d，计算前一天可以使用：last-day,yesterday或者-1days</p>
<pre>sh-3.2# <strong>date -d last-day +%Y%m%d</strong>
20111130
sh-3.2# <strong>date -d yesterday +%Y%m%d</strong>
20111130
sh-3.2# <strong>date -d -1days +%Y%m%d</strong>
20111130</pre>
<p>相应的，计算后一天可以使用：next-day,tomorrow,1days</p>
<pre>date -d next-day +%Y%m%d
date -d tomorrow +%Y%m%d
date -d 1days +%Y%m%d</pre>
<p>其它日期值还有：<strong>last-month,next-month,next-year,last-year&nbsp;</strong></p>
<p>下面四种形式是一样的：</p>
<pre>date -d -1days +%Y%m%d
date -d -1day +%Y%m%d
date -d &#39;1 day ago&#39; +%Y%m%d
date -d &#39;1 days ago&#39; +%Y%m%d</pre>
<p>其它日期分量还有：month,year,hour,minute,second</p>
<pre>date -d 1month +%Y%m%d
date -d -2year +%Y%m%d
date -d -2hours +&quot;%Y%m%d %H:%M:%S&quot;
date -d 60minutes +&quot;%Y%m%d %H:%M:%S&quot;
date -d 3600seconds +&quot;%Y%m%d %H:%M:%S&quot;</pre>
<p>表示今年的11月11日：</p>
<pre>date -d 11nov +%Y%m%d
date -d &#39;Nov 11&#39; +%Y%m%d</pre>
<p>表示2011年12月12日：</p>
<pre>date -d 12dec12  +%Y%m%d
date -d 12dec2012  +%Y%m%d
date -d &#39;12 dec 2012&#39; +%Y%m%d
date -d &#39;dec 12 2012&#39; +%Y%m%d</pre>
<p>查看文件的访问时间、修改时间等信息：stat</p>
<p>如： stat interfaces</p>
<p>输出中包括：文件大小、Inode号、权限、访问时间、修改时间等。</p>
<p>关于ls输出中的时间显示问题：默认ls -l输出的时间以locale形式显示文件的修改时间。以指定格式：&quot;%Y-%m-%d %H:%M:%S&quot; 显示文件的上次访问时间：</p>
<p>sybase@centos5 ~]$ <strong>ls -l --time=atime --time-style=+&quot;%F %T&quot; interfaces</strong><br />
	-rwxr-xr-x 1 sybase sybase 1715 <span style="color:#00f;">2014-12-09 21:33:41</span> interfaces<br />
	[sybase@centos5 ~]$ <strong>stat interfaces</strong><br />
	&nbsp; File: `interfaces&#39;<br />
	&nbsp; Size: 1715&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Blocks: 8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IO Block: 4096&nbsp;&nbsp; regular file<br />
	Device: fd00h/64768d&nbsp;&nbsp;&nbsp; Inode: 21049252&nbsp;&nbsp;&nbsp; Links: 1<br />
	Access: (0755/-rwxr-xr-x)&nbsp; Uid: (&nbsp; 500/&nbsp; sybase)&nbsp;&nbsp; Gid: (&nbsp; 500/&nbsp; sybase)<br />
	Access: <span style="color:#00f;">2014-12-09 21:33:41</span>.000000000 +0800<br />
	Modify: <span style="color:#f00;">2012-06-30 13:13:16.000000000</span> +0800<br />
	Change: 2012-06-30 13:13:16.000000000 +0800<br />
	[sybase@centos5 ~]$<strong> ls -l --time-style=full-iso interfaces</strong><br />
	-rwxr-xr-x 1 sybase sybase 1715 <span style="color:#f00;">2012-06-30 13:13:16.000000000</span> +0800 interfaces</p>
<p>另外一个问题：判断某年的天数，也就是说某年是否闰年？</p>
<p>Year=$(date +%Y)<br />
	if [ $(expr $Year % 400) -eq 0 ] || [ $(expr $Year % 4) -eq 0&nbsp; -a&nbsp; $(expr $Year % 100) -ne 0 ]; then<br />
	&nbsp;&nbsp;&nbsp; echo &quot;$Year has: 366 days&quot;<br />
	else<br />
	&nbsp;&nbsp;&nbsp; echo &quot;$Year has: 365 days&quot;<br />
	fi</p>
<p>参考：<a href="http://blog.chinaunix.net/space.php?uid=9370128&amp;do=blog&amp;id=271932" target="_blank">linux date -d参数用法</a></p>
<p><a href="http://hi.baidu.com/ethnicitybeta/blog/item/bb0d5f3289d108240b55a94e.html" target="_blank">linux date的参数 <br />
	</a></p>
<p><a href="http://hi.baidu.com/lipeng_tsinghua/blog/item/2d2e07d8e517223533fa1c2a.html" target="_blank">Linux date 命令使用技巧<br />
	</a></p>
<div style="clear: both; margin: 10px 0pt; border: 1px dashed rgb(153, 153, 153); font-size: 12px; padding: 5px 10px;">
<li>本文链接地址：<a href="https://www.dbainfo.net/linux-date-count-days-of-month.htm">https://www.dbainfo.net/linux-date-count-days-of-month.htm</a>；</li>
<li>本文为dbainfo个人原创，请在尊重作者劳动成果的前提下进行转载；</li>
<li>转载务必注明原始出处 : <a href="https://www.dbainfo.net/">Sybase数据库技术，数据库恢复专家</a>；</li>
<li>对《<a href="https://www.dbainfo.net/linux-date-count-days-of-month.htm">linux使用date计算某个月份的天数</a>》有何疑问或见解，请在本文下方发表；</li>
<li>对网站还有其他问题或建议，请提交在<a href="https://www.dbainfo.net/messages" target="_blank">留言板</a>，谢谢！</li>
</div>
<h2  class="related_post_title">相关文章</h2><ul class="related_post"><li>2011-12-01 -- <a href="https://www.dbainfo.net/oracle11g-tns-12537-and-ora-609-troubleshooting.htm" title="oracle11g报TNS-12537和ORA-609问题的解决">oracle11g报TNS-12537和ORA-609问题的解决</a> (0)</li><li>2011-06-02 -- <a href="https://www.dbainfo.net/aix-date-change-time-zone-to-get-date.htm" title="aix系统可以用改变时区的方法获取前后N天的日期">aix系统可以用改变时区的方法获取前后N天的日期</a> (0)</li><li>2010-12-23 -- <a href="https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm" title="从sybase向oracle导入时间类型的数据">从sybase向oracle导入时间类型的数据</a> (0)</li><li>2010-12-15 -- <a href="https://www.dbainfo.net/windows-cmd-bat-extract-date-time-format.htm" title="windows cmd下的date，time格式的提取">windows cmd下的date，time格式的提取</a> (0)</li><li>2010-12-15 -- <a href="https://www.dbainfo.net/oracle10g-linux5_4-installer-libxp.htm" title="Linux 5下安装oracle开始遇见的错误 缺少包libXp-1.0.0-8.i386.rpm">Linux 5下安装oracle开始遇见的错误 缺少包libXp-1.0.0-8.i386.rpm</a> (0)</li><li>2010-11-25 -- <a href="https://www.dbainfo.net/cross-platform-migrate-device-file-from-linux-to-windows.htm" title="平台数据库迁移linux >windows">平台数据库迁移linux >windows</a> (0)</li><li>2010-11-09 -- <a href="https://www.dbainfo.net/sybase-ase-current-date-last_day.htm" title="Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法">Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法</a> (0)</li><li>2010-09-09 -- <a href="https://www.dbainfo.net/solaris-remote-ssh-permitrootlogin.htm" title="如何用ROOT用户通过SSH连接到SOLARIS">如何用ROOT用户通过SSH连接到SOLARIS</a> (0)</li><li>2010-08-16 -- <a href="https://www.dbainfo.net/linux-mount-cdrom.htm" title="linux下光盘的挂载使用">linux下光盘的挂载使用</a> (2)</li><li>2009-12-18 -- <a href="https://www.dbainfo.net/install-sybase-at-linux5-4el.htm" title="在linux5.4enterprise下安装sybase成功">在linux5.4enterprise下安装sybase成功</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>https://www.dbainfo.net/linux-date-count-days-of-month.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>aix系统可以用改变时区的方法获取前后N天的日期</title>
		<link>https://www.dbainfo.net/aix-date-change-time-zone-to-get-date.htm</link>
		<comments>https://www.dbainfo.net/aix-date-change-time-zone-to-get-date.htm#comments</comments>
		<pubDate>Thu, 02 Jun 2011 00:49:42 +0000</pubDate>
		<dc:creator>dbainfo</dc:creator>
				<category><![CDATA[Unix&Linux]]></category>
		<category><![CDATA[AIX]]></category>
		<category><![CDATA[date]]></category>

		<guid isPermaLink="false">http://www.dbainfo.net/?p=896</guid>
		<description><![CDATA[在aix系统中date命令没有-d这个选项，不接收输入的日期值。 在aix系统中如果想获得当前时间的前几天或后几天的时间，可以用改变当前时区的方法。 export TZ=BEIST-8是系统当前时间。 调整时区可以改变时间。 例如:获取下一周的时间 export TZ=BEIST-176 ，176是由（24*7+8）获得 &#160;&#160;&#160; 获取上一周的时间 export TZ=BEIST+160 ，160是由（24*7-8）获得 调整时区只改变当前窗口的时间，对服务器没有影响，但是建议在用完时间后将时区调整回来（export TZ=BEIST-8）这样对系统没有任何影响。 函数如下： DaysAfter() { &#160; # $1:the number of days before or after today &#160; # $2:the format of date &#160; CurrentTZ=`echo $TZ` &#160; if (( $1 &#62; 0 )) &#160; then &#160;&#160;&#160; TimeZoneDiff=`echo 24*$1+8 &#124; bc` &#160;&#160;&#160; export TZ=BEIST-$TimeZoneDiff [...]]]></description>
			<content:encoded><![CDATA[<p>在aix系统中date命令没有-d这个选项，不接收输入的日期值。<br />
	在aix系统中如果想获得当前时间的前几天或后几天的时间，可以用改变当前时区的方法。<br />
	export TZ=BEIST-8是系统当前时间。<br />
	调整时区可以改变时间。<br />
	例如:获取下一周的时间 export TZ=BEIST-176 ，176是由（24*7+8）获得<br />
	&nbsp;&nbsp;&nbsp; 获取上一周的时间 export TZ=BEIST+160 ，160是由（24*7-8）获得<br />
	调整时区只改变当前窗口的时间，对服务器没有影响，但是建议在用完时间后将时区调整回来（export TZ=BEIST-8）这样对系统没有任何影响。<br />
	<span id="more-896"></span><br />
	函数如下：</p>
<blockquote>
<p>DaysAfter()<br />
		{<br />
		&nbsp; # $1:the number of days before or after today<br />
		&nbsp; # $2:the format of date<br />
		&nbsp; CurrentTZ=`echo $TZ`<br />
		&nbsp; if (( $1 &gt; 0 )) <br />
		&nbsp; then<br />
		&nbsp;&nbsp;&nbsp; TimeZoneDiff=`echo 24*$1+8 | bc`<br />
		&nbsp;&nbsp;&nbsp; export TZ=BEIST-$TimeZoneDiff<br />
		&nbsp; elif (( $1 == 0 )) ;then<br />
		&nbsp;&nbsp;&nbsp; :<br />
		&nbsp; else<br />
		&nbsp;&nbsp;&nbsp; TimeZoneDiff=`echo -24*$1-8 | bc`<br />
		&nbsp;&nbsp;&nbsp; export TZ=BEIST+$TimeZoneDiff<br />
		&nbsp; fi<br />
		&nbsp; <br />
		&nbsp; date +&quot;$2&quot;<br />
		&nbsp; export TZ=$CurrentTZ<br />
		}</p>
</blockquote>
<p>测试：</p>
<blockquote>
<p>$ DaysAfter 0 &quot;%Y-%m-%d %T&quot;<br />
		2011-06-02 10:37:11<br />
		$ DaysAfter 7 &quot;%Y-%m-%d %T&quot;<br />
		2011-06-09 10:37:29<br />
		$ DaysAfter -7 &quot;%Y-%m-%d %T&quot;<br />
		2011-05-26 10:37:40</p>
</blockquote>
<div style="clear: both; margin: 10px 0pt; border: 1px dashed rgb(153, 153, 153); font-size: 12px; padding: 5px 10px;">
<li>本文链接地址：<a href="https://www.dbainfo.net/aix-date-change-time-zone-to-get-date.htm">https://www.dbainfo.net/aix-date-change-time-zone-to-get-date.htm</a>；</li>
<li>本文为dbainfo个人原创，请在尊重作者劳动成果的前提下进行转载；</li>
<li>转载务必注明原始出处 : <a href="https://www.dbainfo.net/">Sybase数据库技术，数据库恢复专家</a>；</li>
<li>对《<a href="https://www.dbainfo.net/aix-date-change-time-zone-to-get-date.htm">aix系统可以用改变时区的方法获取前后N天的日期</a>》有何疑问或见解，请在本文下方发表；</li>
<li>对网站还有其他问题或建议，请提交在<a href="https://www.dbainfo.net/messages" target="_blank">留言板</a>，谢谢！</li>
</div>
<h2  class="related_post_title">相关文章</h2><ul class="related_post"><li>2011-12-01 -- <a href="https://www.dbainfo.net/linux-date-count-days-of-month.htm" title="linux使用date计算某个月份的天数">linux使用date计算某个月份的天数</a> (0)</li><li>2011-09-19 -- <a href="https://www.dbainfo.net/steps-to-imigrate-sybase-ase-database-on-aix-platform.htm" title="AIX平台上Sybase ASE数据库迁移步骤">AIX平台上Sybase ASE数据库迁移步骤</a> (0)</li><li>2011-09-19 -- <a href="https://www.dbainfo.net/aix-fail-to-create-install-of-aio.htm" title="AIX上未启动异步IO导致Sybase服务创建失败">AIX上未启动异步IO导致Sybase服务创建失败</a> (0)</li><li>2010-12-23 -- <a href="https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm" title="从sybase向oracle导入时间类型的数据">从sybase向oracle导入时间类型的数据</a> (0)</li><li>2010-12-15 -- <a href="https://www.dbainfo.net/windows-cmd-bat-extract-date-time-format.htm" title="windows cmd下的date，time格式的提取">windows cmd下的date，time格式的提取</a> (0)</li><li>2010-11-09 -- <a href="https://www.dbainfo.net/sybase-ase-current-date-last_day.htm" title="Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法">Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法</a> (0)</li><li>2010-03-22 -- <a href="https://www.dbainfo.net/aix-switch-user-environmnet-load.htm" title="AIX下用su切换用户时不能加载环境变量的问题解决">AIX下用su切换用户时不能加载环境变量的问题解决</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>https://www.dbainfo.net/aix-date-change-time-zone-to-get-date.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>从sybase向oracle导入时间类型的数据</title>
		<link>https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm</link>
		<comments>https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm#comments</comments>
		<pubDate>Thu, 23 Dec 2010 02:20:55 +0000</pubDate>
		<dc:creator>dbainfo</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Sybase ASE]]></category>
		<category><![CDATA[ASE]]></category>
		<category><![CDATA[BCP]]></category>
		<category><![CDATA[date]]></category>

		<guid isPermaLink="false">http://www.dbainfo.net/%e4%bb%8esybase%e5%90%91oracle%e5%af%bc%e5%85%a5%e6%97%b6%e9%97%b4%e7%b1%bb%e5%9e%8b%e7%9a%84%e6%95%b0%e6%8d%ae.htm</guid>
		<description><![CDATA[例：有表 --sybase create table t_test( mydate datetime) go --oracle create t_test(mydate date) 方法1：在sybase侧建立视图，然后从导出视图(此方法舍弃了毫秒部分) create view v_test as select convert(varchar(10),pst_exec_stime,111)+&#39; &#39;+convert(varchar(9),pst_exec_stime,8) mydate from t_test go format文件如下(c:\test.fmt) 10.0 1 1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SYBCHAR&#160;&#160;&#160;&#160;&#160; 0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 20&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#34;\t&#34;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; my_date 命令 C:\&#62;bcp testdb..v_test out c:\test.dat -f c:\test.fmt &#8211;Uusername &#8211;Ppassword &#8211;Ssybser Oracle导入control文件如下（c:\test.ctl） Load data Infile &#34;c:\test.dat&#34; Badfile &#34;c:\test.bad&#34; Append into table t_test [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 12px;"><span style="font-family: 宋体;">例：有表 </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">--sybase</span><span style="font-family: 宋体;"> </span></span></p>
<blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">create table t_test(</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">mydate datetime</span></span><span style="font-family: Century;">)</span><span style="font-family: 宋体;"> </span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">go</span><span style="font-family: 宋体;"> </span></span></p>
</blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">--oracle</span><span style="font-family: 宋体;"> </span></span></p>
<blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">create t_test(</span></span><span style="font-family: Century;">mydate date</span><span style="font-family: Century;">)</span><span style="font-family: 宋体;"> </span></p>
</blockquote>
<p><span style="font-size: 14px;"><strong><span style="font-family: 宋体;">方法</span><span style="font-family: Century;">1</span><span style="font-family: 宋体;">：在</span><span style="font-family: Century;">sybase</span><span style="font-family: 宋体;">侧建立视图，然后从导出视图</span><span style="font-family: Century;">(</span><span style="font-family: 宋体;">此方法舍弃了毫秒部分</span><span style="font-family: Century;">)</span><span style="font-family: 宋体;"> </span></strong></span></p>
<blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">create view v_test as </span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">select </span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">convert(varchar(10),pst_exec_stime,111)+&#39; &#39;+convert(varchar(9),pst_exec_stime,8) mydate</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">from t_test</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">go<span id="more-627"></span></span><span style="font-family: 宋体;"> </span></span></p>
</blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">format</span><span style="font-family: 宋体;">文件如下</span><span style="font-family: Century;">(c:\test.fmt)</span><span style="font-family: 宋体;"> </span></span></p>
<blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">10.0</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">1</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYBCHAR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;\t&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my_date</span><span style="font-family: 宋体;"> </span></span></p>
</blockquote>
<p><span style="font-size: 12px;"><span style="font-family: 宋体;">命令 </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">C:\&gt;<strong>bcp testdb..v_test out c:\test.dat -f c:\test.fmt &ndash;Uusername &ndash;Ppassword &ndash;Ssybser </strong></span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Oracle</span><span style="font-family: 宋体;">导入</span><span style="font-family: Century;">control</span><span style="font-family: 宋体;">文件如下（</span><span style="font-family: Century;">c:\test.ctl</span><span style="font-family: 宋体;">） </span></span></p>
<blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Load data</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Infile &quot;c:\test.dat&quot;</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Badfile &quot;c:\test.bad&quot;</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Append into table t_test</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Fields terminated by</span><span style="font-family: 宋体;">&#39;</span><span style="font-family: Century;">\t</span><span style="font-family: 宋体;">&#39;</span><span style="font-family: Century;">(</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Mydate &quot;yyyy/mm/dd hh24:mi:ss&quot;</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">)</span><span style="font-family: 宋体;"> </span></span></p>
</blockquote>
<p><span style="font-size: 12px;"><span style="font-family: 宋体;">命令 </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">C:\&gt;<strong>sqlldr <a href="mailto:username/password@sid"><span style="color: blue; text-decoration: underline;">username/password@sid</span></a> control=&quot;c:\test.ctl&quot; log=&quot;test.log&quot;</strong></span><span style="font-family: 宋体;"> </span></span></p>
<p><strong><span style="font-size: 14px;"><span style="font-family: 宋体;">方法</span><span style="font-family: Century;">2</span><span style="font-family: 宋体;">：和方法</span><span style="font-family: Century;">1</span><span style="font-family: 宋体;">类似不过不用建视图（此方法舍弃了毫秒部分） </span></span></strong></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">format</span><span style="font-family: 宋体;">文件如下</span><span style="font-family: Century;">(c:\test.fmt)</span><span style="font-family: 宋体;"> </span></span></p>
<blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">10.0</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">1</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYBCHAR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;\t&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my_date</span><span style="font-family: 宋体;"> </span></span></p>
</blockquote>
<p><span style="font-size: 12px;"><span style="font-family: 宋体;">命令 </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">C:\&gt;<strong>bcp testdb..t_test out c:\test.dat -f c:\test.fmt &ndash;Uusername &ndash;Ppassword &ndash;Ssybser </strong></span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Oracle</span><span style="font-family: 宋体;">导入</span><span style="font-family: Century;">control</span><span style="font-family: 宋体;">文件如下（</span><span style="font-family: Century;">c:\test.ctl</span><span style="font-family: 宋体;">） </span></span></p>
<blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Load data</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Infile &quot;c:\test.dat&quot;</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Badfile &quot;c:\test.bad&quot;</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Append into table t_test</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Fields terminated by</span><span style="font-family: 宋体;">&#39;</span><span style="font-family: Century;">\t</span><span style="font-family: 宋体;">&#39;</span><span style="font-family: Century;">(</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Mydate &quot;DECODE(:mydate,NULL,TO_DATE(&#39;&#39;,&#39;MM-DD-YYYY&#39;),TO_DATE(SUBSTRB(:mydate,1,instrb(:mydate,&#39;:&#39;,-1)-1)||&#39; &#39;|| SUBSTRB(:mydate,-2),,&#39;Mon dd yyyy hh:mi:ss PM&#39;))&quot;</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">)</span><span style="font-family: 宋体;"> </span></span></p>
</blockquote>
<p><span style="font-size: 12px;"><span style="font-family: 宋体;">命令 </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">C:\&gt;<strong>sqlldr <a href="mailto:username/password@sid"><span style="color: blue; text-decoration: underline;">username/password@sid</span></a> control=&quot;c:\test.ctl&quot; log=&quot;test.log&quot;</strong></span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: 宋体;">如果</span><span style="font-family: Century;">sybase</span><span style="font-family: 宋体;">和</span><span style="font-family: Century;">oracle</span><span style="font-family: 宋体;">的语言不一致，即导入的</span><span style="font-family: Century;">am/pm</span><span style="font-family: 宋体;">保留字为上午</span><span style="font-family: Century;">/</span><span style="font-family: 宋体;">下午什么的可以在</span><span style="font-family: Century;">sqlldr</span><span style="font-family: 宋体;">之前执行如下命令，转换成和</span><span style="font-family: Century;">sybase</span><span style="font-family: 宋体;">一致的语言 </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">C:\&gt;set NLS_LANG=American(</span><span style="font-family: 宋体;">美国语</span><span style="font-family: Century;">)</span><span style="font-family: 宋体;"> </span></span></p>
<p><strong><span style="font-size: 14px;"><span style="font-family: 宋体;">方法</span><span style="font-family: Century;">3</span><span style="font-family: 宋体;">：</span><span style="font-family: Century;">9i</span><span style="font-family: 宋体;">以上版本适用，在方法</span><span style="font-family: Century;">2</span><span style="font-family: 宋体;">的基础上进行改动即可（此方法保留毫秒部分） </span></span></strong></p>
<p><span style="font-size: 12px;"><span style="font-family: 宋体;">将方法</span><span style="font-family: Century;">2</span><span style="font-family: 宋体;">的</span><span style="font-family: Century;">Oracle</span><span style="font-family: 宋体;">导入</span><span style="font-family: Century;">control</span><span style="font-family: 宋体;">文件修改如下（</span><span style="font-family: Century;">c:\test.ctl</span><span style="font-family: 宋体;">） </span></span></p>
<blockquote>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Load data</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Infile &quot;c:\test.dat&quot;</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Badfile &quot;c:\test.bad&quot;</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Append into table t_test</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Fields terminated by</span><span style="font-family: 宋体;">&#39;</span><span style="font-family: Century;">\t</span><span style="font-family: 宋体;">&#39;</span><span style="font-family: Century;">(</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">Mydate timestamp &quot;MON DD YYYY HH:MI:SS:FF3AM&quot;</span><span style="font-family: 宋体;"> </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: Century;">)</span><span style="font-family: 宋体;"> </span></span></p>
</blockquote>
<p><span style="font-size: 12px;"><span style="font-family: 宋体;">其他同方法</span><span style="font-family: Century;">2 </span></span></p>
<p><span style="font-size: 12px;"><span style="font-family: 宋体;">转自：</span><span style="font-family: Century;">http://hi.baidu.com/teemzhang/blog/item/bc709a8625b9503a66096e0f.html</span></span></p>
<div style="clear: both; margin: 10px 0pt; border: 1px dashed rgb(153, 153, 153); font-size: 12px; padding: 5px 10px;">
<li>本文链接地址：<a href="https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm">https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm</a>；</li>
<li>本文为dbainfo个人原创，请在尊重作者劳动成果的前提下进行转载；</li>
<li>转载务必注明原始出处 : <a href="https://www.dbainfo.net/">Sybase数据库技术，数据库恢复专家</a>；</li>
<li>对《<a href="https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm">从sybase向oracle导入时间类型的数据</a>》有何疑问或见解，请在本文下方发表；</li>
<li>对网站还有其他问题或建议，请提交在<a href="https://www.dbainfo.net/messages" target="_blank">留言板</a>，谢谢！</li>
</div>
<h2  class="related_post_title">相关文章</h2><ul class="related_post"><li>2011-10-14 -- <a href="https://www.dbainfo.net/history-of-common-databases.htm" title="各数据库的发展历史">各数据库的发展历史</a> (0)</li><li>2010-11-09 -- <a href="https://www.dbainfo.net/sybase-ase-current-date-last_day.htm" title="Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法">Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法</a> (0)</li><li>2019-04-12 -- <a href="https://www.dbainfo.net/sybase-ase-asa-recovery-service.htm" title="Sybase ASE及SQL Anywhere数据库修复专家">Sybase ASE及SQL Anywhere数据库修复专家</a> (0)</li><li>2015-01-16 -- <a href="https://www.dbainfo.net/one-way-to-recover-master-configuration-area.htm" title="master数据库配置区域(configuration area)损坏的一种修复方法">master数据库配置区域(configuration area)损坏的一种修复方法</a> (1)</li><li>2014-10-10 -- <a href="https://www.dbainfo.net/ase-object-name-length-limit.htm" title="ASE对象名称长度限制">ASE对象名称长度限制</a> (0)</li><li>2014-06-09 -- <a href="https://www.dbainfo.net/count_all_tables_rowcount.htm" title="统计用户数据库内所有表的行数">统计用户数据库内所有表的行数</a> (0)</li><li>2013-11-19 -- <a href="https://www.dbainfo.net/showplan_html_format.htm" title="以HTML格式显示ASE查询计划">以HTML格式显示ASE查询计划</a> (0)</li><li>2013-11-11 -- <a href="https://www.dbainfo.net/ase-15-0-3-for-windows-installation5.htm" title="Sybase ASE 15.0.3 for windows平台安装文档 – 5、安装后的配置工作">Sybase ASE 15.0.3 for windows平台安装文档 – 5、安装后的配置工作</a> (1)</li><li>2013-11-11 -- <a href="https://www.dbainfo.net/ase-15-0-3-for-windows-installation4.htm" title="Sybase ASE 15.0.3 for windows平台安装文档 – 4、安装Sybase数据库服务">Sybase ASE 15.0.3 for windows平台安装文档 – 4、安装Sybase数据库服务</a> (0)</li><li>2013-11-11 -- <a href="https://www.dbainfo.net/ase-15-0-3-for-windows-installation3.htm" title="Sybase ASE 15.0.3 for windows平台安装文档 – 3、升级到 Sybase 15.0.3 ESD #3">Sybase ASE 15.0.3 for windows平台安装文档 – 3、升级到 Sybase 15.0.3 ESD #3</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>windows cmd下的date，time格式的提取</title>
		<link>https://www.dbainfo.net/windows-cmd-bat-extract-date-time-format.htm</link>
		<comments>https://www.dbainfo.net/windows-cmd-bat-extract-date-time-format.htm#comments</comments>
		<pubDate>Wed, 15 Dec 2010 09:58:04 +0000</pubDate>
		<dc:creator>dbainfo</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[bat]]></category>
		<category><![CDATA[date]]></category>

		<guid isPermaLink="false">http://www.dbainfo.net/windows-cmd%e4%b8%8b%e7%9a%84date%ef%bc%8ctime%e6%a0%bc%e5%bc%8f%e7%9a%84%e6%8f%90%e5%8f%96%ef%bc%81.htm</guid>
		<description><![CDATA[纠结了很久了。最近在研究7z的时候，才知道如何使用cmd下的date和time 例如我要生成一个D盘下的200909文件夹， 代码： MD D:\%date:~0,4%%date:~,2% time和date的用法类似。。。。。就不列举了。给大家一个参考 境变量替换已如下增强: &#160; %PATH:str1=str2% &#160; &#160; 会扩展 &#160; PATH &#160; 环境变量，用 &#160; &#34;str2&#34; &#160; 代替扩展结果中的每个 &#160; &#34;str1&#34;。要有效地从扩展结果中删除所有的 &#160; &#34;str1&#34;，&#34;str2&#34; &#160; 可以是空的。&#34;str1&#34; &#160; 可以以星号打头；在这种情况下，&#34;str1&#34; &#160; 会从扩展结果的开始到 &#160; str1 &#160; 剩余部分第一次出现的地方，都一直保持相配。也可以为扩展名指定子字符串。 &#160; %PATH:~10,5% &#160; &#160; 会扩展 &#160; PATH &#160; 环境变量，然后只使用在扩展结果中从第 &#160; 11 &#160; 个(偏移量10)字符开始的五个字符。如果没有指定长度，则采用默认值，即变量数值的余数。如果两个数字(偏移量和长度)都是负数，使用的数字则是环境变量数值长度加上指定的偏移量或长度。 &#160; %PATH:~-10% &#160; &#160; 会提取 &#160; PATH &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 14px;"><span style="font-family: 宋体;">纠结了很久了。最近在研究7z的时候，才知道如何使用cmd下的date和time </span></span></p>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">例如我要生成一个D盘下的200909文件夹， </span></span></p>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">代码：</span></span></p>
<blockquote>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">MD D:\%date:~0,4%%date:~,2% </span></span></p>
</blockquote>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">time和date的用法类似。。。。。就不列举了。给大家一个参考 </span></span></p>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">境变量替换已如下增强: &nbsp; </span></span></p>
<blockquote>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">%PATH:str1=str2% &nbsp; </span></span></p>
</blockquote>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">&nbsp; 会扩展 &nbsp; PATH &nbsp; 环境变量，用 &nbsp; &quot;str2&quot; &nbsp; 代替扩展结果中的每个 &nbsp; &quot;str1&quot;。要有效地从扩展结果中删除所有的 &nbsp; &quot;str1&quot;，&quot;str2&quot; &nbsp; 可以是空的。&quot;str1&quot; &nbsp; 可以以星号打头；在这种情况下，&quot;str1&quot; &nbsp; 会从扩展结果的开始到 &nbsp; str1 &nbsp; 剩余部分第一次出现的地方，都一直保持相配。也可以为扩展名指定子字符串。 &nbsp; </span></span></p>
<blockquote>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">%PATH:~10,5% &nbsp; </span></span></p>
</blockquote>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">&nbsp; 会扩展 &nbsp; PATH &nbsp; 环境变量，然后只使用在扩展结果中从第 &nbsp; 11 &nbsp; 个(偏移量10)字符开始的五个字符。如果没有指定长度，则采用默认值，即变量数值的余数。如果两个数字(偏移量和长度)都是负数，使用的数字则是环境变量数值长度加上指定的偏移量或长度。 &nbsp; </span></span></p>
<blockquote>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">%PATH:~-10% &nbsp; </span></span></p>
</blockquote>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">&nbsp; 会提取 &nbsp; PATH &nbsp; 变量的最后十个字符。 &nbsp; </span></span></p>
<blockquote>
<p><span style="font-size: 14px;"><span style="font-family: 宋体;">%PATH:~0,-2% &nbsp; </span></span></p>
</blockquote>
<p><span style="font-size: 14px;">&nbsp; &nbsp;&nbsp; <span style="font-family: 宋体;">会提取 &nbsp; PATH &nbsp; 变量的所有字符，除了最后两个。但是需要注意window 2000和xp有一定的区别，自己去体会！ </span></span></p>
<p>转自：http://blog.csdn.net/gltianwen/archive/2009/09/07/4527420.aspx</p>
<div style="clear: both; margin: 10px 0pt; border: 1px dashed rgb(153, 153, 153); font-size: 12px; padding: 5px 10px;">
<li>本文链接地址：<a href="https://www.dbainfo.net/windows-cmd-bat-extract-date-time-format.htm">https://www.dbainfo.net/windows-cmd-bat-extract-date-time-format.htm</a>；</li>
<li>本文为dbainfo个人原创，请在尊重作者劳动成果的前提下进行转载；</li>
<li>转载务必注明原始出处 : <a href="https://www.dbainfo.net/">Sybase数据库技术，数据库恢复专家</a>；</li>
<li>对《<a href="https://www.dbainfo.net/windows-cmd-bat-extract-date-time-format.htm">windows cmd下的date，time格式的提取</a>》有何疑问或见解，请在本文下方发表；</li>
<li>对网站还有其他问题或建议，请提交在<a href="https://www.dbainfo.net/messages" target="_blank">留言板</a>，谢谢！</li>
</div>
<h2  class="related_post_title">相关文章</h2><ul class="related_post"><li>2011-12-01 -- <a href="https://www.dbainfo.net/linux-date-count-days-of-month.htm" title="linux使用date计算某个月份的天数">linux使用date计算某个月份的天数</a> (0)</li><li>2011-11-17 -- <a href="https://www.dbainfo.net/get-oracle_home-by-reg-query.htm" title="使用bat批处理读取注册表来提取Oracle环境变量的方法">使用bat批处理读取注册表来提取Oracle环境变量的方法</a> (0)</li><li>2011-06-02 -- <a href="https://www.dbainfo.net/aix-date-change-time-zone-to-get-date.htm" title="aix系统可以用改变时区的方法获取前后N天的日期">aix系统可以用改变时区的方法获取前后N天的日期</a> (0)</li><li>2010-12-23 -- <a href="https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm" title="从sybase向oracle导入时间类型的数据">从sybase向oracle导入时间类型的数据</a> (0)</li><li>2010-11-09 -- <a href="https://www.dbainfo.net/sybase-ase-current-date-last_day.htm" title="Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法">Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法</a> (0)</li><li>2010-10-19 -- <a href="https://www.dbainfo.net/database-backup-strategy-delete-n-days-ago-files-for.htm" title="数据库备份策略中删除N天前的备份文件">数据库备份策略中删除N天前的备份文件</a> (0)</li><li>2010-10-19 -- <a href="https://www.dbainfo.net/windows-dos-command-for-loop-control-advance.htm" title="[转]CMD命令行:for命令详解">[转]CMD命令行:for命令详解</a> (0)</li><li>2010-07-27 -- <a href="https://www.dbainfo.net/windows-command-batch-notes.htm" title="windows的cmd命令行备忘，bat命令">windows的cmd命令行备忘，bat命令</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>https://www.dbainfo.net/windows-cmd-bat-extract-date-time-format.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法</title>
		<link>https://www.dbainfo.net/sybase-ase-current-date-last_day.htm</link>
		<comments>https://www.dbainfo.net/sybase-ase-current-date-last_day.htm#comments</comments>
		<pubDate>Tue, 09 Nov 2010 08:22:51 +0000</pubDate>
		<dc:creator>dbainfo</dc:creator>
				<category><![CDATA[Sybase ASE]]></category>
		<category><![CDATA[ASE]]></category>
		<category><![CDATA[create function]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[last_day]]></category>

		<guid isPermaLink="false">http://www.dbainfo.net/?p=396</guid>
		<description><![CDATA[Oracle中查询月底那天的日期的函数为：last_day()。 在ASE中没有对应的函数，在Oracle移植到Sybase的时候，需要手动编写函数来实现，幸亏ASE15.0.2后开始支持自定义函数。 下面提供3种实现查询本月最后一天的日期的SQL语句： 第一种： select dateadd(dd,-1,convert(char(8),(datepart(yy,dateadd(mm,1,getdate()))*10000+datepart(mm,dateadd(mm,1,getdate()))*100+01))) go &#160; 将本月的下一个月的年份和月份提取出来，以数字的形式相加，然后转化成类似YYYYMMDD的这种日期格式。最后直接取下个月的第一天的前一天即可。在ASE中字符串 &#39;20110101&#39; 和 convert(datetime,&#39;20110101&#39;) 是相等的。 &#160; 第二种： select dateadd(dd,-1, convert(datetime,left(convert(varchar, dateadd(mm,1,getdate()) ,112),6) + &#39;01&#39;) ) go 先将当前日期的下一个月的日期显示成YYYYMMDD的格式，取前6个字符和01拼接成下一月的第一天的日期，然后取前一天即可。convert函数中style的样式，请参考：Sybase ASE convert函数中的style日期时间样式 或者下面的写法： select dateadd(dd,-1,&#160; left(convert(varchar, dateadd(mm,1,getdate()) ,112),6) + &#39;01&#39;&#160; ) go 思路是一样的。 &#160; 第三种： SELECT DATEADD(DD, -DAY(DATEADD(MM, 1, getdate() )), DATEADD(MM, 1, getdate() ))&#160; go &#160; 此方法的思路为：计算当前日期的下一月的那天的前N天的日期，N为当前日期在本月的天数。 &#160; 改进成类似Oracle中的last_day()的函数如下：&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Oracle中查询月底那天的日期的函数为：last_day()。 在ASE中没有对应的函数，在Oracle移植到Sybase的时候，需要手动编写函数来实现，幸亏ASE15.0.2后开始支持自定义函数。</p>
<p>下面提供3种实现查询本月最后一天的日期的SQL语句：</p>
<p>
	第一种：</p>
<blockquote>
<p>select dateadd(dd,-1,convert(char(8),(datepart(yy,dateadd(mm,1,getdate()))*10000+datepart(mm,dateadd(mm,1,getdate()))*100+01))) <br />
		go<br />
		&nbsp;</p>
</blockquote>
<p>将本月的下一个月的年份和月份提取出来，以数字的形式相加，然后转化成类似YYYYMMDD的这种日期格式。最后直接取下个月的第一天的前一天即可。在ASE中字符串 &#39;20110101&#39; 和 convert(datetime,&#39;20110101&#39;) 是相等的。</p>
<p>&nbsp;</p>
<p>第二种：<span id="more-396"></span></p>
<blockquote>
<p>select dateadd(dd,-1, convert(datetime,left(convert(varchar, dateadd(mm,1,getdate()) ,112),6) + &#39;01&#39;) )<br />
		go</p>
</blockquote>
<p>先将当前日期的下一个月的日期显示成YYYYMMDD的格式，取前6个字符和01拼接成下一月的第一天的日期，然后取前一天即可。convert函数中style的样式，请参考：<a href="../sybase-ase-convert-function-style-date-time-format.htm" title="Sybase ASE convert函数中的style日期时间样式">Sybase ASE convert函数中的style日期时间样式</a></p>
<p>或者下面的写法：</p>
<blockquote>
<p>select dateadd(dd,-1,&nbsp; left(convert(varchar, dateadd(mm,1,getdate()) ,112),6) + &#39;01&#39;&nbsp; )<br />
		go</p>
</blockquote>
<p>思路是一样的。</p>
<p>&nbsp;</p>
<p>第三种：</p>
<blockquote>
<p>SELECT DATEADD(DD, -DAY(DATEADD(MM, 1, getdate() )), DATEADD(MM, 1, getdate() ))&nbsp; <br />
		go</p>
</blockquote>
<p>&nbsp;</p>
<p>此方法的思路为：计算当前日期的下一月的那天的前N天的日期，N为当前日期在本月的天数。</p>
<p>&nbsp;</p>
<p>改进成类似Oracle中的last_day()的函数如下：&nbsp;</p>
<p>第一种：</p>
<blockquote>
<p>create function last_day(@d datetime)<br />
		returns datetime<br />
		as<br />
		begin<br />
		declare @rtndate datetime<br />
		select @rtndate = dateadd(DD,-day(dateadd(MM,1,@d)),dateadd(MM,1,@d) )<br />
		return @rtndate<br />
		end<br />
		go</p>
</blockquote>
<p>第2种：</p>
<blockquote>
<p>create function dbo.last_day2(@current_date datetime)<br />
		returns datetime<br />
		as<br />
		begin<br />
		&nbsp; return dateadd(dd,-1, left(convert(varchar, dateadd(mm,1,@current_date) ,112),6) + &#39;01&#39;&nbsp; )<br />
		end<br />
		go<br />
		&nbsp;</p>
</blockquote>
<p>&nbsp;</p>
<p>实现效果如下：</p>
<blockquote>
<p>1&gt; select dbo.last_day(getdate()) ,dbo.last_day2(getdate() )<br />
		2&gt; go</p>
<p>		&nbsp;-------------------------- --------------------------<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Nov 30 2010&nbsp; 4:19PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Nov 30 2010 12:00AM</p>
<p>		(1 row affected)<br />
		1&gt; select dbo.last_day(&#39;19991231&#39;) ,dbo.last_day2(&#39;19991231&#39; )<br />
		2&gt; go</p>
<p>		&nbsp;-------------------------- --------------------------<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dec 31 1999 12:00AM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dec 31 1999 12:00AM</p>
<p>		(1 row affected)<br />
		1&gt; select dbo.last_day(&#39;20100228&#39;) ,dbo.last_day2(&#39;20100228&#39; )<br />
		2&gt; go</p>
<p>		&nbsp;-------------------------- --------------------------<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Feb 28 2010 12:00AM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Feb 28 2010 12:00AM</p>
<p>		(1 row affected)<br />
		1&gt; select dbo.last_day(&#39;20000228&#39;) ,dbo.last_day2(&#39;20000228&#39; )<br />
		2&gt; go</p>
<p>		&nbsp;-------------------------- --------------------------<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Feb 29 2000 12:00AM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Feb 29 2000 12:00AM</p>
<p>		(1 row affected)<br />
		1&gt;</p>
</blockquote>
<div style="clear: both; margin: 10px 0pt; border: 1px dashed rgb(153, 153, 153); font-size: 12px; padding: 5px 10px;">
<li>本文链接地址：<a href="https://www.dbainfo.net/sybase-ase-current-date-last_day.htm">https://www.dbainfo.net/sybase-ase-current-date-last_day.htm</a>；</li>
<li>本文为dbainfo个人原创，请在尊重作者劳动成果的前提下进行转载；</li>
<li>转载务必注明原始出处 : <a href="https://www.dbainfo.net/">Sybase数据库技术，数据库恢复专家</a>；</li>
<li>对《<a href="https://www.dbainfo.net/sybase-ase-current-date-last_day.htm">Sybase ASE v15.x中查询本月最后一天的日期的3种实现方法</a>》有何疑问或见解，请在本文下方发表；</li>
<li>对网站还有其他问题或建议，请提交在<a href="https://www.dbainfo.net/messages" target="_blank">留言板</a>，谢谢！</li>
</div>
<h2  class="related_post_title">相关文章</h2><ul class="related_post"><li>2010-12-23 -- <a href="https://www.dbainfo.net/import-datetime-date-to-oracle-from-sybase-ase.htm" title="从sybase向oracle导入时间类型的数据">从sybase向oracle导入时间类型的数据</a> (0)</li><li>2019-04-12 -- <a href="https://www.dbainfo.net/sybase-ase-asa-recovery-service.htm" title="Sybase ASE及SQL Anywhere数据库修复专家">Sybase ASE及SQL Anywhere数据库修复专家</a> (0)</li><li>2015-01-16 -- <a href="https://www.dbainfo.net/one-way-to-recover-master-configuration-area.htm" title="master数据库配置区域(configuration area)损坏的一种修复方法">master数据库配置区域(configuration area)损坏的一种修复方法</a> (1)</li><li>2014-10-10 -- <a href="https://www.dbainfo.net/ase-object-name-length-limit.htm" title="ASE对象名称长度限制">ASE对象名称长度限制</a> (0)</li><li>2014-06-09 -- <a href="https://www.dbainfo.net/count_all_tables_rowcount.htm" title="统计用户数据库内所有表的行数">统计用户数据库内所有表的行数</a> (0)</li><li>2013-11-19 -- <a href="https://www.dbainfo.net/showplan_html_format.htm" title="以HTML格式显示ASE查询计划">以HTML格式显示ASE查询计划</a> (0)</li><li>2013-11-11 -- <a href="https://www.dbainfo.net/ase-15-0-3-for-windows-installation5.htm" title="Sybase ASE 15.0.3 for windows平台安装文档 – 5、安装后的配置工作">Sybase ASE 15.0.3 for windows平台安装文档 – 5、安装后的配置工作</a> (1)</li><li>2013-11-11 -- <a href="https://www.dbainfo.net/ase-15-0-3-for-windows-installation4.htm" title="Sybase ASE 15.0.3 for windows平台安装文档 – 4、安装Sybase数据库服务">Sybase ASE 15.0.3 for windows平台安装文档 – 4、安装Sybase数据库服务</a> (0)</li><li>2013-11-11 -- <a href="https://www.dbainfo.net/ase-15-0-3-for-windows-installation3.htm" title="Sybase ASE 15.0.3 for windows平台安装文档 – 3、升级到 Sybase 15.0.3 ESD #3">Sybase ASE 15.0.3 for windows平台安装文档 – 3、升级到 Sybase 15.0.3 ESD #3</a> (0)</li><li>2013-11-11 -- <a href="https://www.dbainfo.net/ase-15-0-3-for-windows-installation2.htm" title="Sybase ASE 15.0.3 for windows平台安装文档 – 2、安装Sybase ASE程序">Sybase ASE 15.0.3 for windows平台安装文档 – 2、安装Sybase ASE程序</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>https://www.dbainfo.net/sybase-ase-current-date-last_day.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
