<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx</link><description>Today I was trying to generate a filename based on the current date in a batch file. After doing some searching here is what I came up with: @ For /F "tokens=2,3,4 delims=/ " %%A in ( 'Date /t' ) do @( Set Month=%%A Set Day=%%B Set Year=%%C ) @ echo DAY</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#7300583</link><pubDate>Tue, 05 Jan 2010 09:09:31 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7300583</guid><dc:creator>Mejner</dc:creator><author>Mejner</author><description>&lt;p&gt;And a Swedish verison:&lt;/p&gt;
&lt;p&gt;@For /F &amp;quot;tokens=3,2,1 delims=- &amp;quot; %%A in (&amp;#39;Date /t&amp;#39;) do @( &lt;/p&gt;
&lt;p&gt;Set Day=%%A &lt;/p&gt;
&lt;p&gt;Set Month=%%B &lt;/p&gt;
&lt;p&gt;Set Year=%%C &lt;/p&gt;
&lt;p&gt;) &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7300583" width="1" height="1"&gt;</description></item><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#7267739</link><pubDate>Tue, 01 Dec 2009 10:06:08 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7267739</guid><dc:creator>Richard Quadling</dc:creator><author>Richard Quadling</author><description>&lt;p&gt;Though one issue exists if a user is using long date parts for their short date (set via the regional settings in the control panel).&lt;/p&gt;
&lt;p&gt;As long as the parts are dd, mm and yyyy and separated by one of &amp;#39;-./&amp;#39; then all should be well. The order is all handled - yyyy-mm-dd, mm-dd-yyyy, dd-mm-yyyy, etc.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7267739" width="1" height="1"&gt;</description></item><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#7267735</link><pubDate>Tue, 01 Dec 2009 10:00:42 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7267735</guid><dc:creator>Richard Quadling</dc:creator><author>Richard Quadling</author><description>&lt;p&gt;This is what I use. Works for all our servers and workstations.&lt;/p&gt;
&lt;p&gt;@ECHO OFF&lt;/p&gt;
&lt;p&gt;FOR /F &amp;quot;tokens=1-6 delims=.-/: &amp;quot; %%A IN (&amp;quot;%DATE% %TIME%&amp;quot;) DO (&lt;/p&gt;
&lt;p&gt;	FOR /F &amp;quot;tokens=2-4 skip=1 delims=(.-/)&amp;quot; %%G IN (&amp;#39;VER^|DATE&amp;#39;) DO (&lt;/p&gt;
&lt;p&gt;		SET %%G=%%A&lt;/p&gt;
&lt;p&gt;		SET %%H=%%B&lt;/p&gt;
&lt;p&gt;		SET %%I=%%C&lt;/p&gt;
&lt;p&gt;		SET HH=%%D&lt;/p&gt;
&lt;p&gt;		SET II=%%E&lt;/p&gt;
&lt;p&gt;		SET SS=%%F&lt;/p&gt;
&lt;p&gt;	)&lt;/p&gt;
&lt;p&gt;)&lt;/p&gt;
&lt;p&gt;ECHO YY = %YY%&lt;/p&gt;
&lt;p&gt;ECHO MM = %MM%&lt;/p&gt;
&lt;p&gt;ECHO DD = %DD%&lt;/p&gt;
&lt;p&gt;ECHO HH = %HH%&lt;/p&gt;
&lt;p&gt;ECHO II = %II%&lt;/p&gt;
&lt;p&gt;ECHO SS = %SS%&lt;/p&gt;
&lt;p&gt;One issue is DST. There seems to be no way to deal with this from the command prompt.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7267735" width="1" height="1"&gt;</description></item><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#7230122</link><pubDate>Wed, 14 Oct 2009 23:22:40 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7230122</guid><dc:creator>Buffme</dc:creator><author>Buffme</author><description>&lt;p&gt;For /f &amp;quot;tokens=1,2,3,4,5 delims=/. &amp;quot; %%a in (&amp;#39;date/T&amp;#39;) do set CDate=%%d-%%b-%%c&lt;/p&gt;
&lt;p&gt;@echo data = %CDate%&lt;/p&gt;
&lt;p&gt;This is in the Year-Month-Day that is most common now days&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7230122" width="1" height="1"&gt;</description></item><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#7119707</link><pubDate>Fri, 12 Jun 2009 19:02:17 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7119707</guid><dc:creator>plowther</dc:creator><author>plowther</author><description>&lt;p&gt;Files in windows exp can&amp;#39;t contain the &amp;quot;/&amp;quot; character, it causes issues.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7119707" width="1" height="1"&gt;</description></item><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#7115448</link><pubDate>Wed, 10 Jun 2009 04:22:47 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7115448</guid><dc:creator>cbryant</dc:creator><author>cbryant</author><description>&lt;p&gt;Hi, I need to change to date format of a file xxxxx.txt2009-05-10&lt;/p&gt;
&lt;p&gt;to &lt;/p&gt;
&lt;p&gt;xxxxx.txt2009/05/10&lt;/p&gt;
&lt;p&gt;Is there an easy wasy to do this?&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7115448" width="1" height="1"&gt;</description></item><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#7114374</link><pubDate>Tue, 09 Jun 2009 12:11:47 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7114374</guid><dc:creator>Chandra</dc:creator><author>Chandra</author><description>&lt;p&gt;Very very useful :) Thanks a lot.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7114374" width="1" height="1"&gt;</description></item><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#7078554</link><pubDate>Fri, 08 May 2009 15:08:34 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7078554</guid><dc:creator>toufiqkm</dc:creator><author>toufiqkm</author><description>&lt;p&gt;I am using Windows XP Pro... whoever gave the last solution deserves a big thanks.. I was looking for this code... but you made a little mistake.. coz Win XP uses this format Day mm-dd-yyyy &amp;nbsp;the actual coding should be :&lt;/p&gt;
&lt;p&gt;@echo off&lt;/p&gt;
&lt;p&gt;SET Month=%DATE:~4,2%&lt;/p&gt;
&lt;p&gt;if %Month%==01 set Month=JAN&lt;/p&gt;
&lt;p&gt;if %Month%==02 set Month=FEB&lt;/p&gt;
&lt;p&gt;if %Month%==03 set Month=MAR&lt;/p&gt;
&lt;p&gt;if %Month%==04 set Month=APR&lt;/p&gt;
&lt;p&gt;if %Month%==05 set Month=MAY&lt;/p&gt;
&lt;p&gt;if %Month%==06 set Month=JUN&lt;/p&gt;
&lt;p&gt;if %Month%==07 set Month=JUL&lt;/p&gt;
&lt;p&gt;if %Month%==08 set Month=AUG&lt;/p&gt;
&lt;p&gt;if %Month%==09 set Month=SEP&lt;/p&gt;
&lt;p&gt;if %Month%==10 set Month=OCT&lt;/p&gt;
&lt;p&gt;if %Month%==11 set Month=NOV&lt;/p&gt;
&lt;p&gt;if %Month%==12 set Month=DEC&lt;/p&gt;
&lt;p&gt;echo %Month%&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7078554" width="1" height="1"&gt;</description></item><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#7045795</link><pubDate>Tue, 14 Apr 2009 07:55:17 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7045795</guid><dc:creator>iceblitz</dc:creator><author>iceblitz</author><description>&lt;p&gt;Fantastic. this is exactly what i needed to create a series of backups.&lt;/p&gt;
&lt;p&gt;Thanx a lot.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7045795" width="1" height="1"&gt;</description></item><item><title>re: Parsing Date in a Batch File</title><link>http://weblogs.asp.net/whaggard/archive/2005/08/18/423029.aspx#6914713</link><pubDate>Wed, 18 Feb 2009 12:38:58 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6914713</guid><dc:creator>Joel</dc:creator><author>Joel</author><description>&lt;p&gt;Thanks - this post is really useful. There may well be a better way, but the following will convert the month to a Mid name:&lt;/p&gt;
&lt;p&gt;@echo off&lt;/p&gt;
&lt;p&gt;SET Month=%DATE:~3,2%&lt;/p&gt;
&lt;p&gt;if %Month%==01 set Month=JAN&lt;/p&gt;
&lt;p&gt;if %Month%==02 set Month=FEB&lt;/p&gt;
&lt;p&gt;if %Month%==03 set Month=MAR&lt;/p&gt;
&lt;p&gt;if %Month%==04 set Month=APR&lt;/p&gt;
&lt;p&gt;if %Month%==05 set Month=MAY&lt;/p&gt;
&lt;p&gt;if %Month%==06 set Month=JUN&lt;/p&gt;
&lt;p&gt;if %Month%==07 set Month=JUL&lt;/p&gt;
&lt;p&gt;if %Month%==08 set Month=AUG&lt;/p&gt;
&lt;p&gt;if %Month%==09 set Month=SEP&lt;/p&gt;
&lt;p&gt;if %Month%==10 set Month=OCT&lt;/p&gt;
&lt;p&gt;if %Month%==11 set Month=NOV&lt;/p&gt;
&lt;p&gt;if %Month%==12 set Month=DEC&lt;/p&gt;
&lt;p&gt;echo %Month%&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6914713" width="1" height="1"&gt;</description></item></channel></rss>